Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more sensors & basic Siren (switch) support #84

Merged
merged 44 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
103912f
Add device class CO2
iMicknl Jun 22, 2020
30c7aed
Return measurement based on state
iMicknl Jun 22, 2020
a393355
Fix co2 and add RainSensor
iMicknl Jun 22, 2020
5c98271
Add Rain State
iMicknl Jun 22, 2020
9fdf5b6
Fix binary sensor
iMicknl Jun 22, 2020
63c7d40
Add support for motion sensors
iMicknl Jun 22, 2020
eb11b73
Add support for water sensor
iMicknl Jun 22, 2020
c160042
Fix AirSensor mapping
iMicknl Jun 22, 2020
c578f8e
Add siren support and remove optimistic mode from switch
iMicknl Jun 22, 2020
fec3d18
Style fixes
iMicknl Jun 22, 2020
e796a4a
Add all state to attr
iMicknl Jun 22, 2020
55a2535
Add battery state percentage
iMicknl Jun 22, 2020
33e40ad
Remove todo
iMicknl Jun 22, 2020
aeaa5b9
Battery state hacks
iMicknl Jun 22, 2020
f36db7e
Base icons on device classes
iMicknl Jun 22, 2020
9d7aa89
Update changelog
iMicknl Jun 22, 2020
398ec03
Fix style
iMicknl Jun 22, 2020
a5ea19c
Clean up device_state_attributes
iMicknl Jun 22, 2020
9f2c0b4
Style fix
iMicknl Jun 22, 2020
14d712c
Refactor
iMicknl Jun 22, 2020
26aa512
[fix] Fixed incorrect call to properties.
vlebourl Jun 24, 2020
48ad83e
[fix] Fix command 'ringWithSingleSimpleSequence'
vlebourl Jun 24, 2020
626e61a
[hack] Added ad hoc values to ringWithSingleSimpleSequence
vlebourl Jun 25, 2020
1ff43c2
Merge branch 'master' into refactor_sensor
iMicknl Jul 5, 2020
6d670c6
Make sensor.py more readable
iMicknl Jul 5, 2020
df6893e
Lint fixes
iMicknl Jul 5, 2020
28fe52e
Fix RainSensor const
iMicknl Jul 6, 2020
4df0486
Add WindSensor
iMicknl Jul 6, 2020
047e845
Add support for WindSpeed
iMicknl Jul 6, 2020
07ff932
Add support for VibrationSensor (part of ContactSensor)
iMicknl Jul 6, 2020
e49b534
Add SunSensor support
iMicknl Jul 6, 2020
deb91b4
Switch to const
iMicknl Jul 6, 2020
bdcd8a8
Update README
iMicknl Jul 6, 2020
3d9fd80
Formatting fix
iMicknl Jul 6, 2020
7bc7e50
Add CO sensor
iMicknl Jul 6, 2020
581aa75
Improved comment
iMicknl Jul 6, 2020
f1e7533
Add fix for the future
iMicknl Jul 6, 2020
2caf995
Fix sensor lint
iMicknl Jul 6, 2020
fcf03cc
Add CarButtonSensor
iMicknl Jul 6, 2020
794243f
Fix isort
iMicknl Jul 6, 2020
7563876
Revert changelog
iMicknl Jul 6, 2020
edc8383
Add comment
iMicknl Jul 6, 2020
42f2a17
Improve icon values
iMicknl Jul 6, 2020
edb75d5
Simplify icon()
iMicknl Jul 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 30 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,36 @@ If your device is not supported, it will show the following message in the debug

`DEBUG (MainThread) [custom_components.tahoma] Unsupported Tahoma device (internal:TSKAlarmComponent).`

| Somfy uiClass | Home Assistant platform |
| ----------------- | ----------------------- |
| HeatingSystem | climate |
| Awning | cover |
| Curtain | cover |
| ExteriorScreen | cover |
| Gate | cover |
| GarageDoor | cover |
| Pergola | cover |
| RollerShutter | cover |
| SwingingShutter | cover |
| Window | cover |
| AirSensor | sensor |
| ElectricitySensor | sensor |
| HumiditySensor | sensor |
| LightSensor | sensor |
| TemperatureSensor | sensor |
| DoorLock | lock |
| OnOff | switch |
| ContactSensor | binary_sensor |
| OccupancySensor | binary_sensor |
| SmokeSensor | binary_sensor |
| WindowHandle | binary_sensor |
| Light | light |

## Not supported (yet)
iMicknl marked this conversation as resolved.
Show resolved Hide resolved

| Somfy uiClass |
| --------------------- |
| RemoteController |
| Alarm |
| EvoHome |
| HitachiHeatingSystem |
| ExteriorHeatingSystem |
| Fan |
| Siren |
| MusicPlayer |
| VentilationSystem |
| Somfy uiClass | Home Assistant platform |
| -------------------- | ----------------------- |
| HeatingSystem | climate |
| Awning | cover |
| Curtain | cover |
| ExteriorScreen | cover |
| Gate | cover |
| GarageDoor | cover |
| Pergola | cover |
| RollerShutter | cover |
| SwingingShutter | cover |
| Window | cover |
| AirSensor | sensor |
| ElectricitySensor | sensor |
| HumiditySensor | sensor |
| LightSensor | sensor |
| SunSensor | sensor |
| TemperatureSensor | sensor |
| WindSensor | sensor |
| DoorLock | lock |
| OnOff | switch |
| Siren | switch |
| ContactSensor | binary_sensor |
| MotionSensor | binary_sensor |
| OccupancySensor | binary_sensor |
| RainSensor | binary_sensor |
| SmokeSensor | binary_sensor |
| WindowHandle | binary_sensor |
| WaterDetectionSensor | binary_sensor |
| Light | light |

## Advanced

Expand Down
75 changes: 56 additions & 19 deletions custom_components/tahoma/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
"""Support for TaHoma binary sensors."""
from datetime import timedelta
import logging
from typing import Optional

from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON

from .const import (
CORE_BUTTON_STATE,
CORE_CONTACT_STATE,
CORE_GAS_DETECTION_STATE,
CORE_OCCUPANCY_STATE,
CORE_RAIN_STATE,
CORE_SMOKE_STATE,
CORE_WATER_DETECTION_STATE,
DEVICE_CLASS_GAS,
DEVICE_CLASS_RAIN,
DEVICE_CLASS_WATER,
DOMAIN,
IO_VIBRATION_STATE,
TAHOMA_BINARY_SENSOR_DEVICE_CLASSES,
TAHOMA_TYPES,
)
Expand All @@ -25,12 +34,13 @@ async def async_setup_entry(hass, entry, async_add_entities):

data = hass.data[DOMAIN][entry.entry_id]

entities = []
controller = data.get("controller")

for device in data.get("devices"):
if TAHOMA_TYPES[device.uiclass] == "binary_sensor":
entities.append(TahomaBinarySensor(device, controller))
entities = [
TahomaBinarySensor(device, controller)
for device in data.get("devices")
if TAHOMA_TYPES[device.uiclass] == "binary_sensor"
]

async_add_entities(entities)

Expand Down Expand Up @@ -58,6 +68,23 @@ def device_class(self):
or None
)

@property
def icon(self) -> Optional[str]:
"""Return the icon to use in the frontend, if any."""

if self.device_class == DEVICE_CLASS_WATER:
if self.is_on:
return "mdi:water"
else:
return "mdi:water-off"

icons = {
DEVICE_CLASS_GAS: "mdi:waves",
DEVICE_CLASS_RAIN: "mdi:weather-rainy",
}

return icons.get(self.device_class)

def update(self):
"""Update the state."""
if self.should_wait():
Expand All @@ -66,21 +93,31 @@ def update(self):

self.controller.get_states([self.tahoma_device])

if CORE_CONTACT_STATE in self.tahoma_device.active_states:
self.current_value = (
self.tahoma_device.active_states.get(CORE_CONTACT_STATE) == "open"
)

if CORE_OCCUPANCY_STATE in self.tahoma_device.active_states:
self.current_value = (
self.tahoma_device.active_states.get(CORE_OCCUPANCY_STATE)
== "personInside"
)

if CORE_SMOKE_STATE in self.tahoma_device.active_states:
self.current_value = (
self.tahoma_device.active_states.get(CORE_SMOKE_STATE) == "detected"
)
states = self.tahoma_device.active_states

if CORE_CONTACT_STATE in states:
self.current_value = states.get(CORE_CONTACT_STATE) == "open"

if CORE_OCCUPANCY_STATE in states:
self.current_value = states.get(CORE_OCCUPANCY_STATE) == "personInside"

if CORE_SMOKE_STATE in states:
self.current_value = states.get(CORE_SMOKE_STATE) == "detected"

if CORE_RAIN_STATE in states:
self.current_value = states.get(CORE_RAIN_STATE) == "detected"

if CORE_WATER_DETECTION_STATE in states:
self.current_value = states.get(CORE_WATER_DETECTION_STATE) == "detected"

if CORE_GAS_DETECTION_STATE in states:
self.current_value = states.get(CORE_GAS_DETECTION_STATE) == "detected"

if IO_VIBRATION_STATE in states:
self.current_value = states.get(IO_VIBRATION_STATE) == "detected"
vlebourl marked this conversation as resolved.
Show resolved Hide resolved

if CORE_BUTTON_STATE in states:
self.current_value = states.get(CORE_BUTTON_STATE) == "pressed"

if self.current_value:
self._state = STATE_ON
Expand Down
39 changes: 37 additions & 2 deletions custom_components/tahoma/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Constants for the TaHoma integration."""

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OCCUPANCY,
DEVICE_CLASS_OPENING,
DEVICE_CLASS_SMOKE,
Expand All @@ -23,6 +24,16 @@

DOMAIN = "tahoma"

DEVICE_CLASS_CO = "co"
DEVICE_CLASS_CO2 = "co2"
DEVICE_CLASS_BUTTON = "button"
DEVICE_CLASS_GAS = "gas"
DEVICE_CLASS_RAIN = "rain"
DEVICE_CLASS_SIREN = "siren"
DEVICE_CLASS_SUN_ENERGY = "sun_energy"
DEVICE_CLASS_WATER = "water"
DEVICE_CLASS_WIND_SPEED = "wind_speed"

# Used to map the Somfy uiClass to the Home Assistant platform
TAHOMA_TYPES = {
"Light": "light",
Expand All @@ -35,11 +46,16 @@
"LightSensor": "sensor",
"DoorLock": "lock",
"OnOff": "switch",
"AirFlowSensor": "binary_sensor", # widgetName, uiClass is AirSensor (sensor)
"WaterDetectionSensor": "binary_sensor", # widgetName, uiClass is HumiditySensor (sensor)
"HumiditySensor": "sensor",
"GarageDoor": "cover",
"CarButtonSensor": "binary_sensor",
"ContactSensor": "binary_sensor",
"RainSensor": "binary_sensor",
"SmokeSensor": "binary_sensor",
"OccupancySensor": "binary_sensor",
"MotionSensor": "binary_sensor",
"WindowHandle": "binary_sensor",
"ExteriorVenetianBlind": "cover",
"Awning": "cover",
Expand All @@ -49,6 +65,9 @@
"SwingingShutter": "cover",
"ElectricitySensor": "sensor",
"AirSensor": "sensor",
"Siren": "switch",
"WindSensor": "sensor",
"SunSensor": "sensor",
}


Expand All @@ -68,13 +87,17 @@
"SwingingShutter": DEVICE_CLASS_SHUTTER,
}


# Used to map the Somfy widget or uiClass to the Home Assistant device classes
TAHOMA_BINARY_SENSOR_DEVICE_CLASSES = {
"AirFlowSensor": DEVICE_CLASS_GAS,
"CarButtonSensor": DEVICE_CLASS_BUTTON,
"SmokeSensor": DEVICE_CLASS_SMOKE,
"OccupancySensor": DEVICE_CLASS_OCCUPANCY,
"MotionSensor": DEVICE_CLASS_MOTION,
"ContactSensor": DEVICE_CLASS_OPENING,
"WindowHandle": DEVICE_CLASS_OPENING,
"RainSensor": DEVICE_CLASS_RAIN,
"WaterDetectionSensor": DEVICE_CLASS_WATER,
}

# Used to map the Somfy widget or uiClass to the Home Assistant device classes
Expand All @@ -83,7 +106,11 @@
"HumiditySensor": DEVICE_CLASS_HUMIDITY,
"LightSensor": DEVICE_CLASS_ILLUMINANCE,
"ElectricitySensor": DEVICE_CLASS_POWER,
"AirSensor": "carbon dioxide",
"COSensor": DEVICE_CLASS_CO,
"CO2Sensor": DEVICE_CLASS_CO2,
"RelativeHumiditySensor": DEVICE_CLASS_HUMIDITY,
"WindSensor": DEVICE_CLASS_WIND_SPEED,
"SunSensor": DEVICE_CLASS_SUN_ENERGY,
}

# TaHoma Attributes
Expand All @@ -96,13 +123,16 @@

# TaHoma internal device states
CORE_BLUE_COLOR_INTENSITY_STATE = "core:BlueColorIntensityState"
CORE_BUTTON_STATE = "core:ButtonState"
CORE_CLOSURE_STATE = "core:ClosureState"
CORE_CO_CONCENTRATION_STATE = "core:COConcentrationState"
CORE_CO2_CONCENTRATION_STATE = "core:CO2ConcentrationState"
CORE_CONTACT_STATE = "core:ContactState"
CORE_DEPLOYMENT_STATE = "core:DeploymentState"
CORE_DEROGATED_TARGET_TEMPERATURE_STATE = "core:DerogatedTargetTemperatureState"
CORE_ELECTRIC_ENERGY_CONSUMPTION_STATE = "core:ElectricEnergyConsumptionState"
CORE_ELECTRIC_POWER_CONSUMPTION_STATE = "core:ElectricPowerConsumptionState"
CORE_GAS_DETECTION_STATE = "core:GasDetectionState"
CORE_GREEN_COLOR_INTENSITY_STATE = "core:GreenColorIntensityState"
CORE_LUMINANCE_STATE = "core:LuminanceState"
CORE_MEMORIZED_1_POSITION_STATE = "core:Memorized1PositionState"
Expand All @@ -111,24 +141,29 @@
CORE_ON_OFF_STATE = "core:OnOffState"
CORE_PEDESTRIAN_POSITION_STATE = "core:PedestrianPositionState"
CORE_PRIORITY_LOCK_TIMER_STATE = "core:PriorityLockTimerState"
CORE_RAIN_STATE = "core:RainState"
CORE_RED_COLOR_INTENSITY_STATE = "core:RedColorIntensityState"
CORE_RELATIVE_HUMIDITY_STATE = "core:RelativeHumidityState"
CORE_RSSI_LEVEL_STATE = "core:RSSILevelState"
CORE_SENSOR_DEFECT_STATE = "core:SensorDefectState"
CORE_SLATS_ORIENTATION_STATE = "core:SlatsOrientationState"
CORE_SMOKE_STATE = "core:SmokeState"
CORE_STATUS_STATE = "core:StatusState"
CORE_SUN_ENERGY_STATE = "core:SunEnergyState"
CORE_TARGET_CLOSURE_STATE = "core:TargetClosureState"
CORE_TARGET_TEMPERATURE_STATE = "core:TargetTemperatureState"
CORE_TEMPERATURE_STATE = "core:TemperatureState"
CORE_VERSION_STATE = "core:VersionState"
CORE_WATER_DETECTION_STATE = "core:WaterDetectionState"
CORE_WINDSPEED_STATE = "core:WindSpeedState"

# IO Devices specific states
IO_MAXIMUM_HEATING_LEVEL_STATE = "io:MaximumHeatingLevelState"
IO_PRIORITY_LOCK_LEVEL_STATE = "io:PriorityLockLevelState"
IO_PRIORITY_LOCK_ORIGINATOR_STATE = "io:PriorityLockOriginatorState"
IO_TARGET_HEATING_LEVEL_STATE = "io:TargetHeatingLevelState"
IO_TIMER_FOR_TRANSITORY_STATE_STATE = "io:TimerForTransitoryStateState"
IO_VIBRATION_STATE = "io:VibrationDetectedState"

# Somfy Thermostat specific states
ST_DEROGATION_TYPE_STATE = "somfythermostat:DerogationTypeState"
Expand Down
5 changes: 0 additions & 5 deletions custom_components/tahoma/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,3 @@ def unique_id(self) -> str:
def name(self):
"""Return the name of the scene."""
return self._name

@property
def device_state_attributes(self):
"""Return the state attributes of the scene."""
return {"tahoma_scene_oid": self.tahoma_scene.oid}
Loading