mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
parent
f02c5f66d6
commit
609263e1bb
@ -16,9 +16,13 @@ from homeassistant.const import (
|
|||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
CONF_SENSORS,
|
CONF_SENSORS,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import (
|
||||||
|
async_dispatcher_connect,
|
||||||
|
async_dispatcher_send,
|
||||||
|
)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.service import verify_domain_control
|
from homeassistant.helpers.service import verify_domain_control
|
||||||
|
|
||||||
@ -104,7 +108,6 @@ async def async_setup(hass, config):
|
|||||||
|
|
||||||
async def async_setup_entry(hass, config_entry):
|
async def async_setup_entry(hass, config_entry):
|
||||||
"""Set up OpenUV as config entry."""
|
"""Set up OpenUV as config entry."""
|
||||||
|
|
||||||
_verify_domain_control = verify_domain_control(hass, DOMAIN)
|
_verify_domain_control = verify_domain_control(hass, DOMAIN)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -230,6 +233,7 @@ class OpenUvEntity(Entity):
|
|||||||
|
|
||||||
def __init__(self, openuv):
|
def __init__(self, openuv):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
|
self._async_unsub_dispatcher_connect = None
|
||||||
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
||||||
self._available = True
|
self._available = True
|
||||||
self._name = None
|
self._name = None
|
||||||
@ -249,3 +253,28 @@ class OpenUvEntity(Entity):
|
|||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the entity."""
|
"""Return the name of the entity."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
async def async_added_to_hass(self):
|
||||||
|
"""Register callbacks."""
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def update():
|
||||||
|
"""Update the state."""
|
||||||
|
self.update_from_latest_data()
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
||||||
|
self.hass, TOPIC_UPDATE, update
|
||||||
|
)
|
||||||
|
|
||||||
|
self.update_from_latest_data()
|
||||||
|
|
||||||
|
async def async_will_remove_from_hass(self):
|
||||||
|
"""Disconnect dispatcher listener when removed."""
|
||||||
|
if self._async_unsub_dispatcher_connect:
|
||||||
|
self._async_unsub_dispatcher_connect()
|
||||||
|
self._async_unsub_dispatcher_connect = None
|
||||||
|
|
||||||
|
def update_from_latest_data(self):
|
||||||
|
"""Update the sensor using the latest data."""
|
||||||
|
raise NotImplementedError
|
||||||
|
@ -3,14 +3,12 @@ import logging
|
|||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
||||||
from homeassistant.util.dt import as_local, parse_datetime, utcnow
|
from homeassistant.util.dt import as_local, parse_datetime, utcnow
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
DATA_OPENUV_CLIENT,
|
DATA_OPENUV_CLIENT,
|
||||||
DATA_PROTECTION_WINDOW,
|
DATA_PROTECTION_WINDOW,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
TOPIC_UPDATE,
|
|
||||||
TYPE_PROTECTION_WINDOW,
|
TYPE_PROTECTION_WINDOW,
|
||||||
OpenUvEntity,
|
OpenUvEntity,
|
||||||
)
|
)
|
||||||
@ -75,24 +73,8 @@ class OpenUvBinarySensor(OpenUvEntity, BinarySensorDevice):
|
|||||||
"""Return a unique, Home Assistant friendly identifier for this entity."""
|
"""Return a unique, Home Assistant friendly identifier for this entity."""
|
||||||
return f"{self._latitude}_{self._longitude}_{self._sensor_type}"
|
return f"{self._latitude}_{self._longitude}_{self._sensor_type}"
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
|
||||||
"""Register callbacks."""
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def update():
|
def update_from_latest_data(self):
|
||||||
"""Update the state."""
|
|
||||||
self.async_schedule_update_ha_state(True)
|
|
||||||
|
|
||||||
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
|
||||||
self.hass, TOPIC_UPDATE, update
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self):
|
|
||||||
"""Disconnect dispatcher listener when removed."""
|
|
||||||
if self._async_unsub_dispatcher_connect:
|
|
||||||
self._async_unsub_dispatcher_connect()
|
|
||||||
|
|
||||||
async def async_update(self):
|
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
data = self.openuv.data[DATA_PROTECTION_WINDOW]
|
data = self.openuv.data[DATA_PROTECTION_WINDOW]
|
||||||
|
|
||||||
|
@ -3,14 +3,12 @@ import logging
|
|||||||
|
|
||||||
from homeassistant.const import TIME_MINUTES
|
from homeassistant.const import TIME_MINUTES
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
||||||
from homeassistant.util.dt import as_local, parse_datetime
|
from homeassistant.util.dt import as_local, parse_datetime
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
DATA_OPENUV_CLIENT,
|
DATA_OPENUV_CLIENT,
|
||||||
DATA_UV,
|
DATA_UV,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
TOPIC_UPDATE,
|
|
||||||
TYPE_CURRENT_OZONE_LEVEL,
|
TYPE_CURRENT_OZONE_LEVEL,
|
||||||
TYPE_CURRENT_UV_INDEX,
|
TYPE_CURRENT_UV_INDEX,
|
||||||
TYPE_CURRENT_UV_LEVEL,
|
TYPE_CURRENT_UV_LEVEL,
|
||||||
@ -135,24 +133,8 @@ class OpenUvSensor(OpenUvEntity):
|
|||||||
"""Return the unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return self._unit
|
return self._unit
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
|
||||||
"""Register callbacks."""
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def update():
|
def update_from_latest_data(self):
|
||||||
"""Update the state."""
|
|
||||||
self.async_schedule_update_ha_state(True)
|
|
||||||
|
|
||||||
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
|
||||||
self.hass, TOPIC_UPDATE, update
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self):
|
|
||||||
"""Disconnect dispatcher listener when removed."""
|
|
||||||
if self._async_unsub_dispatcher_connect:
|
|
||||||
self._async_unsub_dispatcher_connect()
|
|
||||||
|
|
||||||
async def async_update(self):
|
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
data = self.openuv.data[DATA_UV].get("result")
|
data = self.openuv.data[DATA_UV].get("result")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user