diff --git a/homeassistant/components/notion/__init__.py b/homeassistant/components/notion/__init__.py index d06827ffd7d..4aa8447eb9a 100644 --- a/homeassistant/components/notion/__init__.py +++ b/homeassistant/components/notion/__init__.py @@ -9,7 +9,7 @@ from aionotion import async_get_client from aionotion.errors import InvalidCredentialsError, NotionError from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_ATTRIBUTION, CONF_PASSWORD, CONF_USERNAME +from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import ( @@ -24,7 +24,7 @@ from homeassistant.helpers.update_coordinator import ( UpdateFailed, ) -from .const import DATA_COORDINATOR, DOMAIN, LOGGER +from .const import DOMAIN, LOGGER PLATFORMS = ["binary_sensor", "sensor"] @@ -39,9 +39,6 @@ CONFIG_SCHEMA = cv.deprecated(DOMAIN) async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Notion as a config entry.""" - hass.data.setdefault(DOMAIN, {}) - hass.data[DOMAIN][entry.entry_id] = {} - if not entry.unique_id: hass.config_entries.async_update_entry( entry, unique_id=entry.data[CONF_USERNAME] @@ -99,7 +96,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] = coordinator hass.config_entries.async_setup_platforms(entry, PLATFORMS) @@ -157,7 +155,7 @@ class NotionEntity(CoordinatorEntity): via_device=(DOMAIN, bridge.get("hardware_id")), ) - self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION} + self._attr_extra_state_attributes = {} self._attr_name = f'{sensor["name"]}: {description.name}' self._attr_unique_id = ( f'{sensor_id}_{coordinator.data["tasks"][task_id]["task_type"]}' diff --git a/homeassistant/components/notion/binary_sensor.py b/homeassistant/components/notion/binary_sensor.py index ab3d0775436..42e32b1e19c 100644 --- a/homeassistant/components/notion/binary_sensor.py +++ b/homeassistant/components/notion/binary_sensor.py @@ -22,7 +22,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import NotionEntity from .const import ( - DATA_COORDINATOR, DOMAIN, LOGGER, SENSOR_BATTERY, @@ -122,7 +121,7 @@ async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Notion sensors based on a config entry.""" - coordinator = hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR] + coordinator = hass.data[DOMAIN][entry.entry_id] async_add_entities( [ diff --git a/homeassistant/components/notion/config_flow.py b/homeassistant/components/notion/config_flow.py index 84fe69eb61a..cdaab389dc7 100644 --- a/homeassistant/components/notion/config_flow.py +++ b/homeassistant/components/notion/config_flow.py @@ -44,23 +44,22 @@ class NotionFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): assert self._username assert self._password + errors = {} session = aiohttp_client.async_get_clientsession(self.hass) try: await async_get_client(self._username, self._password, session=session) except InvalidCredentialsError: - return self.async_show_form( - step_id=step_id, - data_schema=schema, - errors={"base": "invalid_auth"}, - description_placeholders={CONF_USERNAME: self._username}, - ) + errors["base"] = "invalid_auth" except NotionError as err: LOGGER.error("Unknown Notion error: %s", err) + errors["base"] = "unknown" + + if errors: return self.async_show_form( step_id=step_id, data_schema=schema, - errors={"base": "unknown"}, + errors=errors, description_placeholders={CONF_USERNAME: self._username}, ) diff --git a/homeassistant/components/notion/const.py b/homeassistant/components/notion/const.py index 5541cfedc70..339d3020734 100644 --- a/homeassistant/components/notion/const.py +++ b/homeassistant/components/notion/const.py @@ -4,8 +4,6 @@ import logging DOMAIN = "notion" LOGGER = logging.getLogger(__package__) -DATA_COORDINATOR = "coordinator" - SENSOR_BATTERY = "low_battery" SENSOR_DOOR = "door" SENSOR_GARAGE_DOOR = "garage_door" diff --git a/homeassistant/components/notion/sensor.py b/homeassistant/components/notion/sensor.py index efb33944990..2e7260080bb 100644 --- a/homeassistant/components/notion/sensor.py +++ b/homeassistant/components/notion/sensor.py @@ -10,7 +10,7 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import NotionEntity -from .const import DATA_COORDINATOR, DOMAIN, LOGGER, SENSOR_TEMPERATURE +from .const import DOMAIN, LOGGER, SENSOR_TEMPERATURE SENSOR_DESCRIPTIONS = ( SensorEntityDescription( @@ -27,7 +27,7 @@ async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Notion sensors based on a config entry.""" - coordinator = hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR] + coordinator = hass.data[DOMAIN][entry.entry_id] async_add_entities( [