diff --git a/homeassistant/components/nws/__init__.py b/homeassistant/components/nws/__init__.py index 80b6e67aa217..eebc2751dfab 100644 --- a/homeassistant/components/nws/__init__.py +++ b/homeassistant/components/nws/__init__.py @@ -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 diff --git a/homeassistant/components/nws/config_flow.py b/homeassistant/components/nws/config_flow.py index b1b5e237b07b..e107d5f54215 100644 --- a/homeassistant/components/nws/config_flow.py +++ b/homeassistant/components/nws/config_flow.py @@ -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) diff --git a/homeassistant/components/nws/coordinator.py b/homeassistant/components/nws/coordinator.py index a838907823f2..4824cbd85217 100644 --- a/homeassistant/components/nws/coordinator.py +++ b/homeassistant/components/nws/coordinator.py @@ -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: