Use EntityStateAttribute enum in NWS (#176382)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
epenet
2026-07-13 12:32:12 +02:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 5d57d3bf20
commit 40ca2bdab2
3 changed files with 15 additions and 13 deletions
+5 -6
View File
@@ -9,11 +9,10 @@ from pynws import NwsNoDataError, SimpleNWS, call_with_retry
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_LATITUDE,
ATTR_LONGITUDE,
CONF_API_KEY,
CONF_LATITUDE,
CONF_LONGITUDE,
EntityStateAttribute,
Platform,
)
from homeassistant.core import Event, EventStateChangedData, HomeAssistant, callback
@@ -102,8 +101,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: NWSConfigEntry) -> bool:
translation_key="entity_unavailable",
translation_placeholders={"entity_id": location_entity_id},
)
latitude = state.attributes[ATTR_LATITUDE]
longitude = state.attributes[ATTR_LONGITUDE]
latitude = state.attributes[EntityStateAttribute.LATITUDE]
longitude = state.attributes[EntityStateAttribute.LONGITUDE]
station = None
else:
latitude = entry.data[CONF_LATITUDE]
@@ -217,8 +216,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: NWSConfigEntry) -> bool:
new_state = event.data["new_state"]
if new_state is None or not has_location(new_state):
return
new_lat = new_state.attributes[ATTR_LATITUDE]
new_lon = new_state.attributes[ATTR_LONGITUDE]
new_lat = new_state.attributes[EntityStateAttribute.LATITUDE]
new_lon = new_state.attributes[EntityStateAttribute.LONGITUDE]
if (
new_lat == entry.runtime_data.latitude
and new_lon == entry.runtime_data.longitude
+7 -4
View File
@@ -9,11 +9,10 @@ import voluptuous as vol
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import (
ATTR_LATITUDE,
ATTR_LONGITUDE,
CONF_API_KEY,
CONF_LATITUDE,
CONF_LONGITUDE,
EntityStateAttribute,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
@@ -134,8 +133,12 @@ class NWSConfigFlow(ConfigFlow, domain=DOMAIN):
self.hass,
{
CONF_API_KEY: user_input[CONF_API_KEY],
CONF_LATITUDE: state.attributes[ATTR_LATITUDE],
CONF_LONGITUDE: state.attributes[ATTR_LONGITUDE],
CONF_LATITUDE: state.attributes[
EntityStateAttribute.LATITUDE
],
CONF_LONGITUDE: state.attributes[
EntityStateAttribute.LONGITUDE
],
},
)
return self.async_create_entry(title=location_entity, data=data)
+3 -3
View File
@@ -8,7 +8,7 @@ import aiohttp
from aiohttp import ClientResponseError
from pynws import NwsError, NwsNoDataError, SimpleNWS, call_with_retry
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CONF_API_KEY
from homeassistant.const import CONF_API_KEY, EntityStateAttribute
from homeassistant.core import HomeAssistant
from homeassistant.helpers import debounce
from homeassistant.helpers.aiohttp_client import async_get_clientsession
@@ -90,8 +90,8 @@ class NWSObservationDataUpdateCoordinator(TimestampDataUpdateCoordinator[None]):
self._location_entity_id,
)
return
new_lat = state.attributes[ATTR_LATITUDE]
new_lon = state.attributes[ATTR_LONGITUDE]
new_lat = state.attributes[EntityStateAttribute.LATITUDE]
new_lon = state.attributes[EntityStateAttribute.LONGITUDE]
if self._previous_position is not None:
prev_lat, prev_lon = self._previous_position
if new_lat == prev_lat and new_lon == prev_lon: