Perform some AirVisual code cleanup (#58858)
This commit is contained in:
parent
f3d5768fb4
commit
39054d656b
2 changed files with 12 additions and 21 deletions
|
@ -16,7 +16,6 @@ from pyairvisual.errors import (
|
|||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
CONF_API_KEY,
|
||||
CONF_IP_ADDRESS,
|
||||
CONF_LATITUDE,
|
||||
|
@ -190,9 +189,6 @@ def _standardize_node_pro_config_entry(hass: HomeAssistant, entry: ConfigEntry)
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up AirVisual as config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = {}
|
||||
|
||||
if CONF_API_KEY in entry.data:
|
||||
_standardize_geography_config_entry(hass, entry)
|
||||
|
||||
|
@ -271,7 +267,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
)
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR] = coordinator
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = {DATA_COORDINATOR: coordinator}
|
||||
|
||||
# Reassess the interval between 2 server requests
|
||||
if CONF_API_KEY in entry.data:
|
||||
|
@ -355,7 +352,7 @@ class AirVisualEntity(CoordinatorEntity):
|
|||
"""Initialize."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
||||
self._attr_extra_state_attributes = {}
|
||||
self._entry = entry
|
||||
self.entity_description = description
|
||||
|
||||
|
|
|
@ -91,6 +91,7 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self, user_input: dict[str, str], integration_type: str
|
||||
) -> FlowResult:
|
||||
"""Validate a Cloud API key."""
|
||||
errors = {}
|
||||
websession = aiohttp_client.async_get_clientsession(self.hass)
|
||||
cloud_api = CloudAPI(user_input[CONF_API_KEY], session=websession)
|
||||
|
||||
|
@ -117,27 +118,20 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
try:
|
||||
await coro
|
||||
except InvalidKeyError:
|
||||
return self.async_show_form(
|
||||
step_id=error_step,
|
||||
data_schema=error_schema,
|
||||
errors={CONF_API_KEY: "invalid_api_key"},
|
||||
)
|
||||
errors[CONF_API_KEY] = "invalid_api_key"
|
||||
except NotFoundError:
|
||||
return self.async_show_form(
|
||||
step_id=error_step,
|
||||
data_schema=error_schema,
|
||||
errors={CONF_CITY: "location_not_found"},
|
||||
)
|
||||
errors[CONF_CITY] = "location_not_found"
|
||||
except AirVisualError as err:
|
||||
LOGGER.error(err)
|
||||
return self.async_show_form(
|
||||
step_id=error_step,
|
||||
data_schema=error_schema,
|
||||
errors={"base": "unknown"},
|
||||
)
|
||||
errors["base"] = "unknown"
|
||||
|
||||
valid_keys.add(user_input[CONF_API_KEY])
|
||||
|
||||
if errors:
|
||||
return self.async_show_form(
|
||||
step_id=error_step, data_schema=error_schema, errors=errors
|
||||
)
|
||||
|
||||
existing_entry = await self.async_set_unique_id(self._geo_id)
|
||||
if existing_entry:
|
||||
self.hass.config_entries.async_update_entry(existing_entry, data=user_input)
|
||||
|
|
Loading…
Add table
Reference in a new issue