Skip to content

Commit

Permalink
Add sensors dynamically based on available device state (#425)
Browse files Browse the repository at this point in the history
* Add temporary state sensor

* Add extra sensors

* Add more states

* Add more sensors

* Create supported_platforms variable

* Use Overkiz label as device name

* Suffix state sensor name with device index

* Avoid to duplicate state key

* Remove now usless rssi level attribute

* Migrate LightSensor to TahomaStateSensor

* Apply linters

* Add PriorityLockOriginatorState sensor

* Bump minimum version to 2021.8

* Remove unneeded value key

* Migrate to SensorEntityDescription

* Small tweaks

* Add battery level

* Remove unused state keys

* Test electricity sensor

* Add extra sensors

* Add sensor

* Add all sensors from sensor.py

* Add smoke text sensor

* Make optional

* Change all sensor to new structure

* Improve sensor definitions

* Ease state

* Ease retrieve of the index

* Rollback device_state_attributes

* Revert battery changes

* Remove const

* Add LightSensor

* Rollback icon logic in cover

* Bugfixes

* Add round for RSSI value

Co-authored-by: Thibaut Etienne <thibaut@etienne.pw>
  • Loading branch information
iMicknl and tetienne committed Aug 10, 2021
1 parent e7a4554 commit 9505d8c
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 197 deletions.
2 changes: 2 additions & 0 deletions custom_components/tahoma/__init__.py
Expand Up @@ -8,6 +8,7 @@
from aiohttp import ClientError, ServerDisconnectedError
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR
from homeassistant.components.scene import DOMAIN as SCENE
from homeassistant.components.sensor import DOMAIN as SENSOR
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_EXCLUDE, CONF_PASSWORD, CONF_SOURCE, CONF_USERNAME
from homeassistant.core import HomeAssistant, ServiceCall
Expand Down Expand Up @@ -208,6 +209,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

# Sensor and Binary Sensor will be added dynamically, based on the device states
supported_platforms.add(BINARY_SENSOR)
supported_platforms.add(SENSOR)

for platform in supported_platforms:
hass.async_create_task(
Expand Down
30 changes: 15 additions & 15 deletions custom_components/tahoma/const.py
Expand Up @@ -4,7 +4,6 @@
from homeassistant.components.cover import DOMAIN as COVER
from homeassistant.components.light import DOMAIN as LIGHT
from homeassistant.components.lock import DOMAIN as LOCK
from homeassistant.components.sensor import DOMAIN as SENSOR
from homeassistant.components.switch import DOMAIN as SWITCH
from homeassistant.components.water_heater import DOMAIN as WATER_HEATER

Expand All @@ -19,6 +18,21 @@
IGNORED_TAHOMA_DEVICES = [
"ProtocolGateway",
"Pod",
# entries mapped to Sensor based on available states
"AirSensor",
"ConsumptionSensor",
"ElectricitySensor",
"GasSensor",
"GenericSensor",
"HumiditySensor",
"LightSensor",
"SunIntensitySensor",
"SunSensor",
"TemperatureSensor",
"ThermalEnergySensor",
"WaterSensor",
"WeatherSensor",
"WindSensor",
# entries mapped to Binary Sensor based on available states
"AirFlowSensor", # widgetName, uiClass is AirSensor (sensor)
"ContactSensor",
Expand All @@ -32,7 +46,6 @@
# Used to map the Somfy widget and ui_class to the Home Assistant platform
TAHOMA_DEVICE_TO_PLATFORM = {
"AdjustableSlatsRollerShutter": COVER,
"AirSensor": SENSOR,
"Alarm": ALARM_CONTROL_PANEL,
"AtlanticElectricalHeater": CLIMATE, # widgetName, uiClass is HeatingSystem (not supported)
"AtlanticElectricalHeaterWithAdjustableTemperatureSetpoint": CLIMATE, # widgetName, uiClass is HeatingSystem (not supported)
Expand All @@ -41,27 +54,21 @@
"AtlanticPassAPCHeatingAndCoolingZone": CLIMATE, # widgetName, uiClass is HeatingSystem (not supported)
"AtlanticPassAPCZoneControl": CLIMATE, # widgetName, uiClass is HeatingSystem (not supported)
"Awning": COVER,
"ConsumptionSensor": SENSOR,
"Curtain": COVER,
"DimmerExteriorHeating": CLIMATE, # widgetName, uiClass is ExteriorHeatingSystem (not supported)
"DomesticHotWaterProduction": WATER_HEATER, # widgetName, uiClass is WaterHeatingSystem (not supported)
"DomesticHotWaterTank": SWITCH, # widgetName, uiClass is WaterHeatingSystem (not supported)
"DoorLock": LOCK,
"ElectricitySensor": SENSOR,
"EvoHomeController": CLIMATE, # widgetName, uiClass is EvoHome (not supported)
"ExteriorScreen": COVER,
"ExteriorVenetianBlind": COVER,
"GarageDoor": COVER,
"GasSensor": SENSOR,
"Gate": COVER,
"GenericSensor": SENSOR,
"HeatingSetPoint": CLIMATE, # widgetName, uiClass is EvoHome (not supported)
"HitachiDHW": WATER_HEATER, # widgetName, uiClass is HitachiHeatingSystem (not supported)
"HitachiAirToWaterHeatingZone": CLIMATE, # widgetName, uiClass is HitachiHeatingSystem (not supported)
"HitachiAirToAirHeatPump": CLIMATE, # widgetName, uiClass is HitachiHeatingSystem (not supported)
"HumiditySensor": SENSOR,
"Light": LIGHT,
"LightSensor": SENSOR,
"MyFoxSecurityCamera": COVER, # widgetName, uiClass is Camera (not supported)
"OnOff": SWITCH,
"Pergola": COVER,
Expand All @@ -73,16 +80,9 @@
"SirenStatus": None, # widgetName, uiClass is Siren (switch)
"SomfyThermostat": CLIMATE, # widgetName, uiClass is HeatingSystem (not supported)
"StatelessExteriorHeating": CLIMATE, # widgetName, uiClass is ExteriorHeatingSystem.
"SunIntensitySensor": SENSOR,
"SunSensor": SENSOR,
"SwimmingPool": SWITCH,
"SwingingShutter": COVER,
"TemperatureSensor": SENSOR,
"ThermalEnergySensor": SENSOR,
"VenetianBlind": COVER,
"WaterSensor": SENSOR,
"WeatherSensor": SENSOR,
"WindSensor": SENSOR,
"Window": COVER,
}

Expand Down
32 changes: 16 additions & 16 deletions custom_components/tahoma/cover_devices/tahoma_cover.py
Expand Up @@ -61,12 +61,12 @@
CORE_TARGET_CLOSURE_STATE = "core:TargetClosureState"
MYFOX_SHUTTER_STATUS_STATE = "myfox:ShutterStatusState"

ICON_LOCK_ALERT = "mdi:lock-alert"
ICON_WEATHER_WINDY = "mdi:weather-windy"

IO_PRIORITY_LOCK_LEVEL_STATE = "io:PriorityLockLevelState"
IO_PRIORITY_LOCK_ORIGINATOR_STATE = "io:PriorityLockOriginatorState"

ICON_LOCK_ALERT = "mdi:lock-alert"
ICON_WEATHER_WINDY = "mdi:weather-windy"

STATE_CLOSED = "closed"

SERVICE_COVER_MY_POSITION = "set_cover_my_position"
Expand Down Expand Up @@ -128,19 +128,6 @@ def is_closed(self):

return None

@property
def icon(self):
"""Return the icon to use in the frontend, if any."""
if (
self.has_state(CORE_PRIORITY_LOCK_TIMER_STATE)
and self.select_state(CORE_PRIORITY_LOCK_TIMER_STATE) > 0
):
if self.select_state(IO_PRIORITY_LOCK_ORIGINATOR_STATE) == "wind":
return ICON_WEATHER_WINDY
return ICON_LOCK_ALERT

return None

async def async_open_cover_tilt(self, **_):
"""Open the cover tilt."""
await self.async_execute_command(self.select_command(*COMMANDS_OPEN_TILT))
Expand Down Expand Up @@ -292,3 +279,16 @@ def supported_features(self):
supported_features |= SUPPORT_MY

return supported_features

@property
def icon(self):
"""Return the icon to use in the frontend, if any."""
if (
self.has_state(CORE_PRIORITY_LOCK_TIMER_STATE)
and self.select_state(CORE_PRIORITY_LOCK_TIMER_STATE) > 0
):
if self.select_state(IO_PRIORITY_LOCK_ORIGINATOR_STATE) == "wind":
return ICON_WEATHER_WINDY
return ICON_LOCK_ALERT

return None

0 comments on commit 9505d8c

Please sign in to comment.