Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 7db25d7
Author: Mick Vleeshouwer <mick@imick.nl>
Date:   Sun Feb 20 13:56:04 2022 -0800

    Backport `binary_sensor` entity (#765)

    * Backport binary_sensor

    * Add missing descriptions

    * Bugfix

commit f7c280d
Author: Mick Vleeshouwer <mick@imick.nl>
Date:   Sun Feb 20 13:50:07 2022 -0800

    Backport number entity (#766)

commit d93ebc7
Author: Mick Vleeshouwer <mick@imick.nl>
Date:   Sun Feb 20 13:45:52 2022 -0800

    Backport button (#772)

commit 6cb325c
Author: Mick Vleeshouwer <mick@imick.nl>
Date:   Sun Feb 20 13:45:41 2022 -0800

    Backport lock (#769)

commit b738bd1
Author: Mick Vleeshouwer <mick@imick.nl>
Date:   Sun Feb 20 13:45:31 2022 -0800

    Backport executor (#771)

    * Backport executor

    * Add linked_device

commit 11a609c
Author: Mick Vleeshouwer <mick@imick.nl>
Date:   Sun Feb 20 13:16:45 2022 -0800

    Backport switch (#774)

    * Backport switch

    * Remove unnecessary climate platform

commit ccb5fdb
Author: Mick Vleeshouwer <mick@imick.nl>
Date:   Sun Feb 20 12:30:22 2022 -0800

    Backport light (#775)

commit 43c5ada
Author: Mick Vleeshouwer <mick@imick.nl>
Date:   Sun Feb 20 12:23:04 2022 -0800

    Backport scene (#770)
  • Loading branch information
iMicknl committed Feb 20, 2022
1 parent 3c6129d commit 15b99d1
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 319 deletions.
102 changes: 64 additions & 38 deletions custom_components/tahoma/binary_sensor.py
@@ -1,147 +1,173 @@
"""Support for Overkiz binary sensors."""
from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass
from typing import cast

from pyoverkiz.enums import OverkizCommandParam, OverkizState
from pyoverkiz.types import StateType as OverkizStateType

from custom_components.tahoma import HomeAssistantOverkizData
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HomeAssistantOverkizData
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
from .entity import OverkizBinarySensorDescription, OverkizDescriptiveEntity
from .entity import OverkizDescriptiveEntity


@dataclass
class OverkizBinarySensorDescriptionMixin:
"""Define an entity description mixin for binary sensor entities."""

value_fn: Callable[[OverkizStateType], bool]


@dataclass
class OverkizBinarySensorDescription(
BinarySensorEntityDescription, OverkizBinarySensorDescriptionMixin
):
"""Class to describe an Overkiz binary sensor."""

BINARY_SENSOR_DESCRIPTIONS = [

BINARY_SENSOR_DESCRIPTIONS: list[OverkizBinarySensorDescription] = [
# RainSensor/RainSensor
OverkizBinarySensorDescription(
key=OverkizState.CORE_RAIN,
name="Rain",
icon="mdi:weather-rainy",
is_on=lambda state: state == OverkizCommandParam.DETECTED,
value_fn=lambda state: state == OverkizCommandParam.DETECTED,
),
# SmokeSensor/SmokeSensor
OverkizBinarySensorDescription(
key=OverkizState.CORE_SMOKE,
name="Smoke",
device_class=BinarySensorDeviceClass.SMOKE,
is_on=lambda state: state == OverkizCommandParam.DETECTED,
value_fn=lambda state: state == OverkizCommandParam.DETECTED,
),
# WaterSensor/WaterDetectionSensor
OverkizBinarySensorDescription(
key=OverkizState.CORE_WATER_DETECTION,
name="Water",
icon="mdi:water",
is_on=lambda state: state == OverkizCommandParam.DETECTED,
value_fn=lambda state: state == OverkizCommandParam.DETECTED,
),
# AirSensor/AirFlowSensor
OverkizBinarySensorDescription(
key=OverkizState.CORE_GAS_DETECTION,
name="Gas",
device_class=BinarySensorDeviceClass.GAS,
is_on=lambda state: state == OverkizCommandParam.DETECTED,
value_fn=lambda state: state == OverkizCommandParam.DETECTED,
),
# OccupancySensor/OccupancySensor
# OccupancySensor/MotionSensor
OverkizBinarySensorDescription(
key=OverkizState.CORE_OCCUPANCY,
name="Occupancy",
device_class=BinarySensorDeviceClass.OCCUPANCY,
is_on=lambda state: state == OverkizCommandParam.PERSON_INSIDE,
value_fn=lambda state: state == OverkizCommandParam.PERSON_INSIDE,
),
# ContactSensor/WindowWithTiltSensor
OverkizBinarySensorDescription(
key=OverkizState.CORE_VIBRATION,
name="Vibration",
device_class=BinarySensorDeviceClass.VIBRATION,
is_on=lambda state: state == OverkizCommandParam.DETECTED,
value_fn=lambda state: state == OverkizCommandParam.DETECTED,
),
# ContactSensor/ContactSensor
OverkizBinarySensorDescription(
key=OverkizState.CORE_CONTACT,
name="Contact",
device_class=BinarySensorDeviceClass.DOOR,
is_on=lambda state: state == OverkizCommandParam.OPEN,
value_fn=lambda state: state == OverkizCommandParam.OPEN,
),
# Siren/SirenStatus
OverkizBinarySensorDescription(
key=OverkizState.CORE_ASSEMBLY,
name="Assembly",
device_class=BinarySensorDeviceClass.PROBLEM,
is_on=lambda state: state == OverkizCommandParam.OPEN,
value_fn=lambda state: state == OverkizCommandParam.OPEN,
),
# Unknown
OverkizBinarySensorDescription(
key=OverkizState.IO_VIBRATION_DETECTED,
name="Vibration",
device_class=BinarySensorDeviceClass.VIBRATION,
is_on=lambda state: state == OverkizCommandParam.DETECTED,
value_fn=lambda state: state == OverkizCommandParam.DETECTED,
),
# DomesticHotWaterProduction/WaterHeatingSystem
OverkizBinarySensorDescription(
key=OverkizState.IO_DHW_BOOST_MODE,
name="Boost Mode",
icon="hass:water-boiler-alert",
is_on=lambda state: state == OverkizCommandParam.ON,
value_fn=lambda state: state == OverkizCommandParam.ON,
),
OverkizBinarySensorDescription(
key=OverkizState.IO_DHW_ABSENCE_MODE,
name="Away Mode",
icon="hass:water-boiler-off",
is_on=lambda state: state == OverkizCommandParam.ON,
value_fn=lambda state: state == OverkizCommandParam.ON,
),
OverkizBinarySensorDescription(
key=OverkizState.IO_OPERATING_MODE_CAPABILITIES,
name="Energy Demand Status",
device_class=BinarySensorDeviceClass.HEAT,
is_on=lambda state: state.get(OverkizCommandParam.ENERGY_DEMAND_STATUS) == 1,
value_fn=lambda state: cast(dict, state).get(
OverkizCommandParam.ENERGY_DEMAND_STATUS
)
== 1,
),
]

SUPPORTED_STATES = {
description.key: description for description in BINARY_SENSOR_DESCRIPTIONS
}


async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
):
"""Set up the Overkiz sensors from a config entry."""
) -> None:
"""Set up the Overkiz binary sensors from a config entry."""
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
entities = []

key_supported_states = {
description.key: description for description in BINARY_SENSOR_DESCRIPTIONS
}
entities: list[OverkizBinarySensor] = []

for device in data.coordinator.data.values():
if (
device.widget not in IGNORED_OVERKIZ_DEVICES
and device.ui_class not in IGNORED_OVERKIZ_DEVICES
device.widget in IGNORED_OVERKIZ_DEVICES
or device.ui_class in IGNORED_OVERKIZ_DEVICES
):
for state in device.definition.states:
if description := key_supported_states.get(state.qualified_name):
entities.append(
OverkizBinarySensor(
device.device_url,
data.coordinator,
description,
)
continue

for state in device.definition.states:
if description := SUPPORTED_STATES.get(state.qualified_name):
entities.append(
OverkizBinarySensor(
device.device_url,
data.coordinator,
description,
)
)

async_add_entities(entities)


class OverkizBinarySensor(OverkizDescriptiveEntity, BinarySensorEntity):
"""Representation of an Overkiz Binary Sensor."""

entity_description: OverkizBinarySensorDescription

@property
def is_on(self):
def is_on(self) -> bool | None:
"""Return the state of the sensor."""
state = self.device.states.get(self.entity_description.key)

if not state:
return None
if state := self.device.states.get(self.entity_description.key):
return self.entity_description.value_fn(state.value)

return self.entity_description.is_on(state.value)
return None
64 changes: 37 additions & 27 deletions custom_components/tahoma/button.py
@@ -1,15 +1,17 @@
"""Support for Overkiz number devices."""
"""Support for Overkiz (virtual) buttons."""
from __future__ import annotations

from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HomeAssistantOverkizData
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
from .entity import OverkizDescriptiveEntity

BUTTON_DESCRIPTIONS = [
BUTTON_DESCRIPTIONS: list[ButtonEntityDescription] = [
# My Position (cover, light)
ButtonEntityDescription(
key="my",
Expand All @@ -18,62 +20,70 @@
),
# Identify
ButtonEntityDescription(
key="identify", # startIdentify and identify are reversed... Remove when fixed server side.
key="identify", # startIdentify and identify are reversed... Swap this when fixed in API.
name="Start Identify",
icon="mdi:human-greeting-variant",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
ButtonEntityDescription(
key="stopIdentify",
name="Stop Identify",
icon="mdi:human-greeting-variant",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
ButtonEntityDescription(
key="startIdentify", # startIdentify and identify are reversed... Remove when fixed server side.
key="startIdentify", # startIdentify and identify are reversed... Swap this when fixed in API.
name="Identify",
icon="mdi:human-greeting-variant",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
entity_category=EntityCategory.DIAGNOSTIC,
),
# RTDIndoorSiren / RTDOutdoorSiren
ButtonEntityDescription(key="dingDong", name="Ding Dong", icon="mdi:bell-ring"),
ButtonEntityDescription(key="bip", name="Bip", icon="mdi:bell-ring"),
ButtonEntityDescription(
key="fastBipSequence", name="Fast Bip Sequence", icon="mdi:bell-ring"
),
ButtonEntityDescription(key="ring", name="Ring", icon="mdi:bell-ring"),
]

SUPPORTED_COMMANDS = {
description.key: description for description in BUTTON_DESCRIPTIONS
}


async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
):
"""Set up the Overkiz number from a config entry."""
) -> None:
"""Set up the Overkiz button from a config entry."""
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]

entities = []

supported_commands = {
description.key: description for description in BUTTON_DESCRIPTIONS
}
entities: list[ButtonEntity] = []

for device in data.coordinator.data.values():
if (
device.widget not in IGNORED_OVERKIZ_DEVICES
and device.ui_class not in IGNORED_OVERKIZ_DEVICES
device.widget in IGNORED_OVERKIZ_DEVICES
or device.ui_class in IGNORED_OVERKIZ_DEVICES
):
for command in device.definition.commands:
if description := supported_commands.get(command.command_name):
entities.append(
OverkizButton(
device.device_url,
data.coordinator,
description,
)
continue

for command in device.definition.commands:
if description := SUPPORTED_COMMANDS.get(command.command_name):
entities.append(
OverkizButton(
device.device_url,
data.coordinator,
description,
)
)

async_add_entities(entities)


class OverkizButton(OverkizDescriptiveEntity, ButtonEntity):
"""Representation of an Overkiz Button entity."""
"""Representation of an Overkiz Button."""

async def async_press(self) -> None:
"""Handle the button press."""
Expand Down
2 changes: 0 additions & 2 deletions custom_components/tahoma/climate.py
Expand Up @@ -30,7 +30,6 @@
SomfyHeatingTemperatureInterface,
)
from .climate_devices.somfy_thermostat import SomfyThermostat
from .climate_devices.stateless_exterior_heating import StatelessExteriorHeating
from .const import DOMAIN

TYPE = {
Expand All @@ -47,7 +46,6 @@
UIWidget.HITACHI_AIR_TO_WATER_HEATING_ZONE: HitachiAirToWaterHeatingZone,
UIWidget.SOMFY_HEATING_TEMPERATURE_INTERFACE: SomfyHeatingTemperatureInterface,
UIWidget.SOMFY_THERMOSTAT: SomfyThermostat,
UIWidget.STATELESS_EXTERIOR_HEATING: StatelessExteriorHeating,
}


Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion custom_components/tahoma/const.py
Expand Up @@ -74,7 +74,7 @@
UIWidget.SIREN_STATUS: None, # widgetName, uiClass is Siren (switch)
UIWidget.SOMFY_HEATING_TEMPERATURE_INTERFACE: Platform.CLIMATE, # widgetName, uiClass is HeatingSystem (not supported)
UIWidget.SOMFY_THERMOSTAT: Platform.CLIMATE, # widgetName, uiClass is HeatingSystem (not supported)
UIWidget.STATELESS_EXTERIOR_HEATING: Platform.CLIMATE, # widgetName, uiClass is ExteriorHeatingSystem.
UIWidget.STATELESS_EXTERIOR_HEATING: Platform.SWITCH, # widgetName, uiClass is ExteriorHeatingSystem (not supported)
UIClass.SWIMMING_POOL: Platform.SWITCH,
UIClass.SWINGING_SHUTTER: Platform.COVER,
UIClass.VENETIAN_BLIND: Platform.COVER,
Expand Down

0 comments on commit 15b99d1

Please sign in to comment.