mirror of
https://github.com/Andre0512/hon.git
synced 2024-11-23 23:01:00 +01:00
Add lock
This commit is contained in:
parent
269a521435
commit
3ed335d356
@ -181,7 +181,6 @@ For every device exists a button under diagnostics which can be used to log all
|
||||
| Aroma Time On | `thermometer` | `number` | `settings.aromaTimeOn` |
|
||||
| Diffuser Level | | `select` | `settings.aromaStatus` |
|
||||
| Light status | | `light` | `settings.lightStatus` |
|
||||
| Lock Status | | `switch` | `lockStatus` |
|
||||
| Mode | `run` | `select` | `settings.machMode` |
|
||||
| Pollen Level | | `number` | `settings.pollenLevel` |
|
||||
| Touch Tone | | `switch` | `touchToneStatus` |
|
||||
@ -192,6 +191,7 @@ For every device exists a button under diagnostics which can be used to log all
|
||||
| CO Level | | `sensor` | `coLevel` |
|
||||
| Error | `math-log` | `sensor` | `errors` |
|
||||
| Humidity | | `sensor` | `humidityIndoor` |
|
||||
| Lock Status | | `lock` | `lockStatus` |
|
||||
| Main Filter Status | | `sensor` | `mainFilterStatus` |
|
||||
| On | `power-cycle` | `binary_sensor` | `attributes.parameters.onOffStatus` |
|
||||
| PM 10 | | `sensor` | `pm10ValueIndoor` |
|
||||
|
@ -19,6 +19,7 @@ PLATFORMS = [
|
||||
"climate",
|
||||
"fan",
|
||||
"light",
|
||||
"lock",
|
||||
]
|
||||
|
||||
APPLIANCES = {
|
||||
|
85
custom_components/hon/lock.py
Normal file
85
custom_components/hon/lock.py
Normal file
@ -0,0 +1,85 @@
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.lock import LockEntity, LockEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import callback
|
||||
from pyhon.parameter.base import HonParameter
|
||||
from pyhon.parameter.range import HonParameterRange
|
||||
|
||||
from .const import DOMAIN
|
||||
from .hon import HonEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
LOCKS: dict[str, tuple[LockEntityDescription, ...]] = {
|
||||
"AP": (
|
||||
LockEntityDescription(
|
||||
key="lockStatus",
|
||||
name="Lock Status",
|
||||
translation_key="mode",
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None:
|
||||
entities = []
|
||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
||||
for description in LOCKS.get(device.appliance_type, []):
|
||||
if (
|
||||
f"settings.{description.key}" not in device.available_settings
|
||||
or device.get(description.key) is None
|
||||
):
|
||||
continue
|
||||
entity = HonLockEntity(hass, entry, device, description)
|
||||
await entity.coordinator.async_config_entry_first_refresh()
|
||||
entities.append(entity)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class HonLockEntity(HonEntity, LockEntity):
|
||||
entity_description: LockEntityDescription
|
||||
|
||||
@property
|
||||
def is_locked(self) -> bool | None:
|
||||
"""Return a boolean for the state of the lock."""
|
||||
"""Return True if entity is on."""
|
||||
return self._device.get(self.entity_description.key, 0) == 1
|
||||
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock method."""
|
||||
setting = self._device.settings[f"settings.{self.entity_description.key}"]
|
||||
if type(setting) == HonParameter:
|
||||
return
|
||||
setting.value = setting.max if isinstance(setting, HonParameterRange) else 1
|
||||
self.async_write_ha_state()
|
||||
await self._device.commands["settings"].send()
|
||||
await self.coordinator.async_refresh()
|
||||
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock method."""
|
||||
setting = self._device.settings[f"settings.{self.entity_description.key}"]
|
||||
if type(setting) == HonParameter:
|
||||
return
|
||||
setting.value = setting.min if isinstance(setting, HonParameterRange) else 0
|
||||
self.async_write_ha_state()
|
||||
await self._device.commands["settings"].send()
|
||||
await self.coordinator.async_refresh()
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return (
|
||||
super().available
|
||||
and int(self._device.get("remoteCtrValid", 1)) == 1
|
||||
and self._device.get("attributes.lastConnEvent.category") != "DISCONNECTED"
|
||||
)
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self, update=True) -> None:
|
||||
value = self._device.get(self.entity_description.key, 0)
|
||||
self._attr_is_locked = self.is_locked
|
||||
if update:
|
||||
self.async_write_ha_state()
|
@ -12,7 +12,6 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
PERCENTAGE,
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
@ -736,7 +735,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
||||
name="VOC",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS,
|
||||
native_unit_of_measurement=CONCENTRATION_PARTS_PER_BILLION,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
translation_key="voc",
|
||||
),
|
||||
HonSensorEntityDescription(
|
||||
|
@ -336,11 +336,6 @@ SWITCHES: dict[str, tuple[HonSwitchEntityDescription, ...]] = {
|
||||
name="Touch Tone",
|
||||
translation_key="touch_tone",
|
||||
),
|
||||
HonSwitchEntityDescription(
|
||||
key="lockStatus",
|
||||
name="Lock Status",
|
||||
translation_key="mode",
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
@ -10,6 +11,7 @@ from custom_components.hon.button import BUTTONS
|
||||
from custom_components.hon.climate import CLIMATES
|
||||
from custom_components.hon.fan import FANS
|
||||
from custom_components.hon.light import LIGHTS
|
||||
from custom_components.hon.lock import LOCKS
|
||||
from custom_components.hon.number import NUMBERS
|
||||
from custom_components.hon.select import SELECTS
|
||||
from custom_components.hon.sensor import SENSORS
|
||||
@ -18,12 +20,13 @@ from custom_components.hon.switch import SWITCHES
|
||||
entities = {
|
||||
"binary_sensor": BINARY_SENSORS,
|
||||
"button": BUTTONS,
|
||||
"light": LIGHTS,
|
||||
"climate": CLIMATES,
|
||||
"fan": FANS,
|
||||
"light": LIGHTS,
|
||||
"lock": LOCKS,
|
||||
"number": NUMBERS,
|
||||
"select": SELECTS,
|
||||
"sensor": SENSORS,
|
||||
"fan": FANS,
|
||||
"switch": SWITCHES,
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,13 @@ if __name__ == "__main__":
|
||||
from custom_components.hon.const import APPLIANCES
|
||||
from custom_components.hon.binary_sensor import BINARY_SENSORS
|
||||
from custom_components.hon.button import BUTTONS
|
||||
from custom_components.hon.light import LIGHTS
|
||||
from custom_components.hon.climate import CLIMATES
|
||||
from custom_components.hon.fan import FANS
|
||||
from custom_components.hon.light import LIGHTS
|
||||
from custom_components.hon.lock import LOCKS
|
||||
from custom_components.hon.number import NUMBERS
|
||||
from custom_components.hon.select import SELECTS
|
||||
from custom_components.hon.sensor import SENSORS
|
||||
from custom_components.hon.fan import FANS
|
||||
from custom_components.hon.switch import (
|
||||
SWITCHES,
|
||||
HonControlSwitchEntityDescription,
|
||||
@ -28,12 +29,13 @@ ENTITY_CATEGORY_SORT = ["control", "config", "sensor"]
|
||||
entities = {
|
||||
"binary_sensor": BINARY_SENSORS,
|
||||
"button": BUTTONS,
|
||||
"light": LIGHTS,
|
||||
"climate": CLIMATES,
|
||||
"fan": FANS,
|
||||
"light": LIGHTS,
|
||||
"lock": LOCKS,
|
||||
"number": NUMBERS,
|
||||
"select": SELECTS,
|
||||
"sensor": SENSORS,
|
||||
"fan": FANS,
|
||||
"switch": SWITCHES,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user