Perform some OpenUV code cleanup (#58864)
This commit is contained in:
parent
568df3d972
commit
198b18dd00
4 changed files with 7 additions and 18 deletions
|
@ -9,7 +9,6 @@ from pyopenuv.errors import OpenUvError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ATTRIBUTION,
|
|
||||||
CONF_API_KEY,
|
CONF_API_KEY,
|
||||||
CONF_BINARY_SENSORS,
|
CONF_BINARY_SENSORS,
|
||||||
CONF_ELEVATION,
|
CONF_ELEVATION,
|
||||||
|
@ -30,7 +29,6 @@ from homeassistant.helpers.service import verify_domain_control
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_FROM_WINDOW,
|
CONF_FROM_WINDOW,
|
||||||
CONF_TO_WINDOW,
|
CONF_TO_WINDOW,
|
||||||
DATA_CLIENT,
|
|
||||||
DATA_PROTECTION_WINDOW,
|
DATA_PROTECTION_WINDOW,
|
||||||
DATA_UV,
|
DATA_UV,
|
||||||
DEFAULT_FROM_WINDOW,
|
DEFAULT_FROM_WINDOW,
|
||||||
|
@ -51,9 +49,6 @@ PLATFORMS = ["binary_sensor", "sensor"]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up OpenUV as config entry."""
|
"""Set up OpenUV as config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
hass.data[DOMAIN][entry.entry_id] = {}
|
|
||||||
|
|
||||||
_verify_domain_control = verify_domain_control(hass, DOMAIN)
|
_verify_domain_control = verify_domain_control(hass, DOMAIN)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -73,7 +68,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
LOGGER.error("Config entry failed: %s", err)
|
LOGGER.error("Config entry failed: %s", err)
|
||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady from err
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_CLIENT] = openuv
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
hass.data[DOMAIN][entry.entry_id] = openuv
|
||||||
|
|
||||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
@_verify_domain_control
|
@_verify_domain_control
|
||||||
|
@ -175,7 +172,7 @@ class OpenUvEntity(Entity):
|
||||||
|
|
||||||
def __init__(self, openuv: OpenUV, description: EntityDescription) -> None:
|
def __init__(self, openuv: OpenUV, description: EntityDescription) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
self._attr_extra_state_attributes = {}
|
||||||
self._attr_should_poll = False
|
self._attr_should_poll = False
|
||||||
self._attr_unique_id = (
|
self._attr_unique_id = (
|
||||||
f"{openuv.client.latitude}_{openuv.client.longitude}_{description.key}"
|
f"{openuv.client.latitude}_{openuv.client.longitude}_{description.key}"
|
||||||
|
|
|
@ -9,13 +9,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.dt import as_local, parse_datetime, utcnow
|
from homeassistant.util.dt import as_local, parse_datetime, utcnow
|
||||||
|
|
||||||
from . import OpenUvEntity
|
from . import OpenUvEntity
|
||||||
from .const import (
|
from .const import DATA_PROTECTION_WINDOW, DOMAIN, LOGGER, TYPE_PROTECTION_WINDOW
|
||||||
DATA_CLIENT,
|
|
||||||
DATA_PROTECTION_WINDOW,
|
|
||||||
DOMAIN,
|
|
||||||
LOGGER,
|
|
||||||
TYPE_PROTECTION_WINDOW,
|
|
||||||
)
|
|
||||||
|
|
||||||
ATTR_PROTECTION_WINDOW_ENDING_TIME = "end_time"
|
ATTR_PROTECTION_WINDOW_ENDING_TIME = "end_time"
|
||||||
ATTR_PROTECTION_WINDOW_ENDING_UV = "end_uv"
|
ATTR_PROTECTION_WINDOW_ENDING_UV = "end_uv"
|
||||||
|
@ -33,7 +27,7 @@ async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up an OpenUV sensor based on a config entry."""
|
"""Set up an OpenUV sensor based on a config entry."""
|
||||||
openuv = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]
|
openuv = hass.data[DOMAIN][entry.entry_id]
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[OpenUvBinarySensor(openuv, BINARY_SENSOR_DESCRIPTION_PROTECTION_WINDOW)]
|
[OpenUvBinarySensor(openuv, BINARY_SENSOR_DESCRIPTION_PROTECTION_WINDOW)]
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,7 +7,6 @@ LOGGER = logging.getLogger(__package__)
|
||||||
CONF_FROM_WINDOW = "from_window"
|
CONF_FROM_WINDOW = "from_window"
|
||||||
CONF_TO_WINDOW = "to_window"
|
CONF_TO_WINDOW = "to_window"
|
||||||
|
|
||||||
DATA_CLIENT = "data_client"
|
|
||||||
DATA_PROTECTION_WINDOW = "protection_window"
|
DATA_PROTECTION_WINDOW = "protection_window"
|
||||||
DATA_UV = "uv"
|
DATA_UV = "uv"
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ from homeassistant.util.dt import as_local, parse_datetime
|
||||||
|
|
||||||
from . import OpenUvEntity
|
from . import OpenUvEntity
|
||||||
from .const import (
|
from .const import (
|
||||||
DATA_CLIENT,
|
|
||||||
DATA_UV,
|
DATA_UV,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
TYPE_CURRENT_OZONE_LEVEL,
|
TYPE_CURRENT_OZONE_LEVEL,
|
||||||
|
@ -122,7 +121,7 @@ async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a OpenUV sensor based on a config entry."""
|
"""Set up a OpenUV sensor based on a config entry."""
|
||||||
openuv = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]
|
openuv = hass.data[DOMAIN][entry.entry_id]
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[OpenUvSensor(openuv, description) for description in SENSOR_DESCRIPTIONS]
|
[OpenUvSensor(openuv, description) for description in SENSOR_DESCRIPTIONS]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue