1 """Support for Niko Home Control."""
3 from __future__
import annotations
5 from datetime
import timedelta
10 import voluptuous
as vol
14 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
27 _LOGGER = logging.getLogger(__name__)
31 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend({vol.Required(CONF_HOST): cv.string})
37 async_add_entities: AddEntitiesCallback,
38 discovery_info: DiscoveryInfoType |
None =
None,
40 """Set up the Niko Home Control light platform."""
41 host = config[CONF_HOST]
44 nhc = nikohomecontrol.NikoHomeControl(
45 {
"ip": host,
"port": 8000,
"timeout": 20000}
48 await niko_data.async_update()
49 except OSError
as err:
50 _LOGGER.error(
"Unable to access %s (%s)", host, err)
51 raise PlatformNotReady
from err
59 """Representation of an Niko Light."""
62 """Set up the Niko Home Control light platform."""
70 if light._state[
"type"] == 2:
75 """Instruct the light to turn on."""
76 _LOGGER.debug(
"Turn on: %s", self.
namename)
77 self.
_light_light.
turn_on(kwargs.get(ATTR_BRIGHTNESS, 255) / 2.55)
80 """Instruct the light to turn off."""
81 _LOGGER.debug(
"Turn off: %s", self.
namename)
85 """Get the latest data from NikoHomeControl API."""
94 """The class for handling data retrieval."""
97 """Set up Niko Home Control Data object."""
104 @Throttle(MIN_TIME_BETWEEN_UPDATES)
106 """Get the latest data from the NikoHomeControl API."""
107 _LOGGER.debug(
"Fetching async state in bulk")
109 self.
datadata = await self.
hasshass.async_add_executor_job(
110 self.
_nhc_nhc.list_actions_raw
113 except OSError
as ex:
114 _LOGGER.error(
"Unable to retrieve data from Niko, %s",
str(ex))
118 """Find and filter state based on action id."""
119 for state
in self.
datadata:
120 if state[
"id"] == aid:
121 return state[
"value1"]
122 _LOGGER.error(
"Failed to retrieve state off unknown light")
set[ColorMode]|set[str]|None supported_color_modes(self)
def __init__(self, hass, nhc)
None turn_on(self, **Any kwargs)
_attr_supported_color_modes
def __init__(self, light, data)
None turn_off(self, **Any kwargs)
str|UndefinedType|None name(self)
str|float get_state(dict[str, float] data, str key)
bool brightness_supported(Iterable[ColorMode|str]|None color_modes)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)