Add support for ELV-SH-CTV Sensor to homematicip_cloud (#143737)

This commit is contained in:
hahn-th 2025-07-08 07:24:55 +02:00 committed by GitHub
parent 7a7e16bbb6
commit f780b9763d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 434 additions and 98 deletions

View File

@ -1,4 +1,15 @@
{
"entity": {
"sensor": {
"tilt_state": {
"state": {
"neutral": "mdi:garage",
"non_neutral": "mdi:garage-open",
"tilted": "mdi:garage-alert"
}
}
}
},
"services": {
"activate_eco_mode_with_duration": {
"service": "mdi:leaf"

View File

@ -11,6 +11,7 @@ from homematicip.base.functionalChannels import (
FunctionalChannel,
)
from homematicip.device import (
Device,
EnergySensorsInterface,
FloorTerminalBlock6,
FloorTerminalBlock10,
@ -31,6 +32,7 @@ from homematicip.device import (
TemperatureHumiditySensorDisplay,
TemperatureHumiditySensorOutdoor,
TemperatureHumiditySensorWithoutDisplay,
TiltVibrationSensor,
WeatherSensor,
WeatherSensorPlus,
WeatherSensorPro,
@ -44,6 +46,7 @@ from homeassistant.components.sensor import (
)
from homeassistant.const import (
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
DEGREE,
LIGHT_LUX,
PERCENTAGE,
UnitOfEnergy,
@ -62,6 +65,11 @@ from .entity import HomematicipGenericEntity
from .hap import HomematicIPConfigEntry, HomematicipHAP
from .helpers import get_channels_from_device
ATTR_ACCELERATION_SENSOR_NEUTRAL_POSITION = "acceleration_sensor_neutral_position"
ATTR_ACCELERATION_SENSOR_TRIGGER_ANGLE = "acceleration_sensor_trigger_angle"
ATTR_ACCELERATION_SENSOR_SECOND_TRIGGER_ANGLE = (
"acceleration_sensor_second_trigger_angle"
)
ATTR_CURRENT_ILLUMINATION = "current_illumination"
ATTR_LOWEST_ILLUMINATION = "lowest_illumination"
ATTR_HIGHEST_ILLUMINATION = "highest_illumination"
@ -89,6 +97,136 @@ ILLUMINATION_DEVICE_ATTRIBUTES = {
"highestIllumination": ATTR_HIGHEST_ILLUMINATION,
}
TILT_STATE_VALUES = ["neutral", "tilted", "non_neutral"]
def get_device_handlers(hap: HomematicipHAP) -> dict[type, Callable]:
"""Generate a mapping of device types to handler functions."""
return {
HomeControlAccessPoint: lambda device: [
HomematicipAccesspointDutyCycle(hap, device)
],
HeatingThermostat: lambda device: [
HomematicipHeatingThermostat(hap, device),
HomematicipTemperatureSensor(hap, device),
],
HeatingThermostatCompact: lambda device: [
HomematicipHeatingThermostat(hap, device),
HomematicipTemperatureSensor(hap, device),
],
HeatingThermostatEvo: lambda device: [
HomematicipHeatingThermostat(hap, device),
HomematicipTemperatureSensor(hap, device),
],
TemperatureHumiditySensorDisplay: lambda device: [
HomematicipTemperatureSensor(hap, device),
HomematicipHumiditySensor(hap, device),
HomematicipAbsoluteHumiditySensor(hap, device),
],
TemperatureHumiditySensorWithoutDisplay: lambda device: [
HomematicipTemperatureSensor(hap, device),
HomematicipHumiditySensor(hap, device),
HomematicipAbsoluteHumiditySensor(hap, device),
],
TemperatureHumiditySensorOutdoor: lambda device: [
HomematicipTemperatureSensor(hap, device),
HomematicipHumiditySensor(hap, device),
HomematicipAbsoluteHumiditySensor(hap, device),
],
RoomControlDeviceAnalog: lambda device: [
HomematicipTemperatureSensor(hap, device),
],
LightSensor: lambda device: [
HomematicipIlluminanceSensor(hap, device),
],
MotionDetectorIndoor: lambda device: [
HomematicipIlluminanceSensor(hap, device),
],
MotionDetectorOutdoor: lambda device: [
HomematicipIlluminanceSensor(hap, device),
],
MotionDetectorPushButton: lambda device: [
HomematicipIlluminanceSensor(hap, device),
],
PresenceDetectorIndoor: lambda device: [
HomematicipIlluminanceSensor(hap, device),
],
SwitchMeasuring: lambda device: [
HomematicipPowerSensor(hap, device),
HomematicipEnergySensor(hap, device),
],
PassageDetector: lambda device: [
HomematicipPassageDetectorDeltaCounter(hap, device),
],
TemperatureDifferenceSensor2: lambda device: [
HomematicpTemperatureExternalSensorCh1(hap, device),
HomematicpTemperatureExternalSensorCh2(hap, device),
HomematicpTemperatureExternalSensorDelta(hap, device),
],
TiltVibrationSensor: lambda device: [
HomematicipTiltStateSensor(hap, device),
HomematicipTiltAngleSensor(hap, device),
],
WeatherSensor: lambda device: [
HomematicipTemperatureSensor(hap, device),
HomematicipHumiditySensor(hap, device),
HomematicipIlluminanceSensor(hap, device),
HomematicipWindspeedSensor(hap, device),
HomematicipAbsoluteHumiditySensor(hap, device),
],
WeatherSensorPlus: lambda device: [
HomematicipTemperatureSensor(hap, device),
HomematicipHumiditySensor(hap, device),
HomematicipIlluminanceSensor(hap, device),
HomematicipWindspeedSensor(hap, device),
HomematicipTodayRainSensor(hap, device),
HomematicipAbsoluteHumiditySensor(hap, device),
],
WeatherSensorPro: lambda device: [
HomematicipTemperatureSensor(hap, device),
HomematicipHumiditySensor(hap, device),
HomematicipIlluminanceSensor(hap, device),
HomematicipWindspeedSensor(hap, device),
HomematicipTodayRainSensor(hap, device),
HomematicipAbsoluteHumiditySensor(hap, device),
],
EnergySensorsInterface: lambda device: _handle_energy_sensor_interface(
hap, device
),
}
def _handle_energy_sensor_interface(
hap: HomematicipHAP, device: Device
) -> list[HomematicipGenericEntity]:
"""Handle energy sensor interface devices."""
result: list[HomematicipGenericEntity] = []
for ch in get_channels_from_device(
device, FunctionalChannelType.ENERGY_SENSORS_INTERFACE_CHANNEL
):
if ch.connectedEnergySensorType == ESI_CONNECTED_SENSOR_TYPE_IEC:
if ch.currentPowerConsumption is not None:
result.append(HmipEsiIecPowerConsumption(hap, device))
if ch.energyCounterOneType != ESI_TYPE_UNKNOWN:
result.append(HmipEsiIecEnergyCounterHighTariff(hap, device))
if ch.energyCounterTwoType != ESI_TYPE_UNKNOWN:
result.append(HmipEsiIecEnergyCounterLowTariff(hap, device))
if ch.energyCounterThreeType != ESI_TYPE_UNKNOWN:
result.append(HmipEsiIecEnergyCounterInputSingleTariff(hap, device))
if ch.connectedEnergySensorType == ESI_CONNECTED_SENSOR_TYPE_GAS:
if ch.currentGasFlow is not None:
result.append(HmipEsiGasCurrentGasFlow(hap, device))
if ch.gasVolume is not None:
result.append(HmipEsiGasGasVolume(hap, device))
if ch.connectedEnergySensorType == ESI_CONNECTED_SENSOR_TYPE_LED:
if ch.currentPowerConsumption is not None:
result.append(HmipEsiLedCurrentPowerConsumption(hap, device))
result.append(HmipEsiLedEnergyCounterHighTariff(hap, device))
return result
async def async_setup_entry(
hass: HomeAssistant,
@ -98,101 +236,29 @@ async def async_setup_entry(
"""Set up the HomematicIP Cloud sensors from a config entry."""
hap = config_entry.runtime_data
entities: list[HomematicipGenericEntity] = []
# Get device handlers dynamically
device_handlers = get_device_handlers(hap)
# Process all devices
for device in hap.home.devices:
if isinstance(device, HomeControlAccessPoint):
entities.append(HomematicipAccesspointDutyCycle(hap, device))
if isinstance(
device,
(
HeatingThermostat,
HeatingThermostatCompact,
HeatingThermostatEvo,
),
):
entities.append(HomematicipHeatingThermostat(hap, device))
entities.append(HomematicipTemperatureSensor(hap, device))
if isinstance(
device,
(
TemperatureHumiditySensorDisplay,
TemperatureHumiditySensorWithoutDisplay,
TemperatureHumiditySensorOutdoor,
WeatherSensor,
WeatherSensorPlus,
WeatherSensorPro,
),
):
entities.append(HomematicipTemperatureSensor(hap, device))
entities.append(HomematicipHumiditySensor(hap, device))
entities.append(HomematicipAbsoluteHumiditySensor(hap, device))
elif isinstance(device, (RoomControlDeviceAnalog,)):
entities.append(HomematicipTemperatureSensor(hap, device))
if isinstance(
device,
(
LightSensor,
MotionDetectorIndoor,
MotionDetectorOutdoor,
MotionDetectorPushButton,
PresenceDetectorIndoor,
WeatherSensor,
WeatherSensorPlus,
WeatherSensorPro,
),
):
entities.append(HomematicipIlluminanceSensor(hap, device))
if isinstance(device, SwitchMeasuring):
entities.append(HomematicipPowerSensor(hap, device))
entities.append(HomematicipEnergySensor(hap, device))
if isinstance(device, (WeatherSensor, WeatherSensorPlus, WeatherSensorPro)):
entities.append(HomematicipWindspeedSensor(hap, device))
if isinstance(device, (WeatherSensorPlus, WeatherSensorPro)):
entities.append(HomematicipTodayRainSensor(hap, device))
if isinstance(device, PassageDetector):
entities.append(HomematicipPassageDetectorDeltaCounter(hap, device))
if isinstance(device, TemperatureDifferenceSensor2):
entities.append(HomematicpTemperatureExternalSensorCh1(hap, device))
entities.append(HomematicpTemperatureExternalSensorCh2(hap, device))
entities.append(HomematicpTemperatureExternalSensorDelta(hap, device))
if isinstance(device, EnergySensorsInterface):
for ch in get_channels_from_device(
device, FunctionalChannelType.ENERGY_SENSORS_INTERFACE_CHANNEL
):
if ch.connectedEnergySensorType == ESI_CONNECTED_SENSOR_TYPE_IEC:
if ch.currentPowerConsumption is not None:
entities.append(HmipEsiIecPowerConsumption(hap, device))
if ch.energyCounterOneType != ESI_TYPE_UNKNOWN:
entities.append(HmipEsiIecEnergyCounterHighTariff(hap, device))
if ch.energyCounterTwoType != ESI_TYPE_UNKNOWN:
entities.append(HmipEsiIecEnergyCounterLowTariff(hap, device))
if ch.energyCounterThreeType != ESI_TYPE_UNKNOWN:
entities.append(
HmipEsiIecEnergyCounterInputSingleTariff(hap, device)
)
for device_class, handler in device_handlers.items():
if isinstance(device, device_class):
entities.extend(handler(device))
if ch.connectedEnergySensorType == ESI_CONNECTED_SENSOR_TYPE_GAS:
if ch.currentGasFlow is not None:
entities.append(HmipEsiGasCurrentGasFlow(hap, device))
if ch.gasVolume is not None:
entities.append(HmipEsiGasGasVolume(hap, device))
if ch.connectedEnergySensorType == ESI_CONNECTED_SENSOR_TYPE_LED:
if ch.currentPowerConsumption is not None:
entities.append(HmipEsiLedCurrentPowerConsumption(hap, device))
entities.append(HmipEsiLedEnergyCounterHighTariff(hap, device))
if isinstance(
device,
(
# Handle floor terminal blocks separately
floor_terminal_blocks = (
FloorTerminalBlock6,
FloorTerminalBlock10,
FloorTerminalBlock12,
WiredFloorTerminalBlock12,
),
):
)
entities.extend(
HomematicipFloorTerminalBlockMechanicChannelValve(
hap, device, channel=channel.index
)
for device in hap.home.devices
if isinstance(device, floor_terminal_blocks)
for channel in device.functionalChannels
if isinstance(channel, FloorTerminalBlockMechanicChannel)
and getattr(channel, "valvePosition", None) is not None
@ -201,6 +267,57 @@ async def async_setup_entry(
async_add_entities(entities)
class HomematicipTiltAngleSensor(HomematicipGenericEntity, SensorEntity):
"""Representation of the HomematicIP tilt angle sensor."""
_attr_native_unit_of_measurement = DEGREE
_attr_state_class = SensorStateClass.MEASUREMENT_ANGLE
def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the tilt angle sensor device."""
super().__init__(hap, device, post="Tilt Angle")
@property
def native_value(self) -> int | None:
"""Return the state."""
return getattr(self.functional_channel, "absoluteAngle", None)
class HomematicipTiltStateSensor(HomematicipGenericEntity, SensorEntity):
"""Representation of the HomematicIP tilt sensor."""
_attr_device_class = SensorDeviceClass.ENUM
_attr_options = TILT_STATE_VALUES
_attr_translation_key = "tilt_state"
def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the tilt sensor device."""
super().__init__(hap, device, post="Tilt State")
@property
def native_value(self) -> str | None:
"""Return the state."""
tilt_state = getattr(self.functional_channel, "tiltState", None)
return tilt_state.lower() if tilt_state is not None else None
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the tilt sensor."""
state_attr = super().extra_state_attributes
state_attr[ATTR_ACCELERATION_SENSOR_NEUTRAL_POSITION] = getattr(
self.functional_channel, "accelerationSensorNeutralPosition", None
)
state_attr[ATTR_ACCELERATION_SENSOR_TRIGGER_ANGLE] = getattr(
self.functional_channel, "accelerationSensorTriggerAngle", None
)
state_attr[ATTR_ACCELERATION_SENSOR_SECOND_TRIGGER_ANGLE] = getattr(
self.functional_channel, "accelerationSensorSecondTriggerAngle", None
)
return state_attr
class HomematicipFloorTerminalBlockMechanicChannelValve(
HomematicipGenericEntity, SensorEntity
):

View File

@ -27,6 +27,17 @@
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
}
},
"entity": {
"sensor": {
"tilt_state": {
"state": {
"neutral": "Neutral",
"non_neutral": "Non-neutral",
"tilted": "Tilted"
}
}
}
},
"exceptions": {
"access_point_not_found": {
"message": "No matching access point found for access point ID {id}"

View File

@ -8297,6 +8297,152 @@
"type": "DOOR_BELL_CONTACT_INTERFACE",
"updateState": "UP_TO_DATE"
},
"3014F7110000000000000CTV": {
"availableFirmwareVersion": "0.0.0",
"connectionType": "HMIP_RF",
"deviceArchetype": "HMIP",
"firmwareVersion": "1.0.6",
"firmwareVersionInteger": 65542,
"functionalChannels": {
"0": {
"busConfigMismatch": null,
"coProFaulty": false,
"coProRestartNeeded": false,
"coProUpdateFailure": false,
"configPending": false,
"controlsMountingOrientation": null,
"daliBusState": null,
"defaultLinkedGroup": [],
"deviceAliveSignalEnabled": null,
"deviceCommunicationError": null,
"deviceDriveError": null,
"deviceDriveModeError": null,
"deviceId": "3014F7110000000000000CTV",
"deviceOperationMode": null,
"deviceOverheated": false,
"deviceOverloaded": false,
"devicePowerFailureDetected": false,
"deviceUndervoltage": false,
"displayContrast": null,
"displayMode": null,
"displayMountingOrientation": null,
"dutyCycle": false,
"functionalChannelType": "DEVICE_BASE",
"groupIndex": 0,
"groups": [
"00000000-0000-0000-0000-000000000041",
"00000000-0000-0000-0000-000000000042"
],
"index": 0,
"invertedDisplayColors": null,
"label": "",
"lockJammed": null,
"lowBat": false,
"mountingOrientation": null,
"multicastRoutingEnabled": false,
"operationDays": null,
"particulateMatterSensorCommunicationError": null,
"particulateMatterSensorError": null,
"powerShortCircuit": null,
"profilePeriodLimitReached": null,
"routerModuleEnabled": false,
"routerModuleSupported": false,
"rssiDeviceValue": -102,
"rssiPeerValue": null,
"sensorCommunicationError": null,
"sensorError": null,
"shortCircuitDataLine": null,
"supportedOptionalFeatures": {
"IFeatureBusConfigMismatch": false,
"IFeatureDeviceCoProError": false,
"IFeatureDeviceCoProRestart": false,
"IFeatureDeviceCoProUpdate": false,
"IFeatureDeviceCommunicationError": false,
"IFeatureDeviceDaliBusError": false,
"IFeatureDeviceDriveError": false,
"IFeatureDeviceDriveModeError": false,
"IFeatureDeviceIdentify": false,
"IFeatureDeviceOverheated": false,
"IFeatureDeviceOverloaded": false,
"IFeatureDeviceParticulateMatterSensorCommunicationError": false,
"IFeatureDeviceParticulateMatterSensorError": false,
"IFeatureDevicePowerFailure": false,
"IFeatureDeviceSensorCommunicationError": false,
"IFeatureDeviceSensorError": false,
"IFeatureDeviceTemperatureHumiditySensorCommunicationError": false,
"IFeatureDeviceTemperatureHumiditySensorError": false,
"IFeatureDeviceTemperatureOutOfRange": false,
"IFeatureDeviceUndervoltage": false,
"IFeatureMulticastRouter": false,
"IFeaturePowerShortCircuit": false,
"IFeatureProfilePeriodLimit": false,
"IFeatureRssiValue": true,
"IFeatureShortCircuitDataLine": false,
"IOptionalFeatureDefaultLinkedGroup": false,
"IOptionalFeatureDeviceAliveSignalEnabled": false,
"IOptionalFeatureDeviceErrorLockJammed": false,
"IOptionalFeatureDeviceOperationMode": false,
"IOptionalFeatureDisplayContrast": false,
"IOptionalFeatureDisplayMode": false,
"IOptionalFeatureDutyCycle": true,
"IOptionalFeatureInvertedDisplayColors": false,
"IOptionalFeatureLowBat": true,
"IOptionalFeatureMountingOrientation": false,
"IOptionalFeatureOperationDays": false
},
"temperatureHumiditySensorCommunicationError": null,
"temperatureHumiditySensorError": null,
"temperatureOutOfRange": false,
"unreach": false
},
"1": {
"absoluteAngle": 89,
"accelerationSensorEventFilterPeriod": 3.0,
"accelerationSensorMode": "TILT",
"accelerationSensorNeutralPosition": "VERTICAL",
"accelerationSensorSecondTriggerAngle": 75,
"accelerationSensorSensitivity": "SENSOR_RANGE_2G_2PLUS_SENSE",
"accelerationSensorTriggerAngle": 20,
"accelerationSensorTriggered": false,
"channelRole": "ACCELERATION_SENSOR",
"deviceId": "3014F7110000000000000CTV",
"functionalChannelType": "TILT_VIBRATION_SENSOR_CHANNEL",
"groupIndex": 1,
"groups": [
"00000000-0000-0000-0000-000000000023",
"00000000-0000-0000-0000-000000000041",
"00000000-0000-0000-0000-000000000043"
],
"index": 1,
"label": "",
"supportedOptionalFeatures": {
"IFeatureLightGroupSensorChannel": false,
"IOptionalFeatureAbsoluteAngle": true,
"IOptionalFeatureAccelerationSensorTiltTriggerAngle": true,
"IOptionalFeatureTiltDetection": true,
"IOptionalFeatureTiltState": true,
"IOptionalFeatureTiltVisualization": true
},
"tiltState": "NEUTRAL",
"tiltVisualization": "GARAGE_DOOR"
}
},
"homeId": "00000000-0000-0000-0000-000000000001",
"id": "3014F7110000000000000CTV",
"label": "Neigungssensor Tor",
"lastStatusUpdate": 1741379260066,
"liveUpdateState": "LIVE_UPDATE_NOT_SUPPORTED",
"manuallyUpdateForced": false,
"manufacturerCode": 9,
"measuredAttributes": {},
"modelId": 580,
"modelType": "ELV-SH-CTV",
"oem": "eQ-3",
"permanentlyReachable": false,
"serializedGlobalTradeItemNumber": "3014F7110000000000000CTV",
"type": "TILT_VIBRATION_SENSOR_COMPACT",
"updateState": "UP_TO_DATE"
},
"3014F71100000000000SVCTH": {
"availableFirmwareVersion": "1.0.10",
"connectionType": "HMIP_RF",

View File

@ -22,7 +22,7 @@ async def test_hmip_load_all_supported_devices(
test_devices=None, test_groups=None
)
assert len(mock_hap.hmip_device_by_entity_id) == 325
assert len(mock_hap.hmip_device_by_entity_id) == 331
async def test_hmip_remove_device(

View File

@ -13,6 +13,9 @@ from homeassistant.components.homematicip_cloud.entity import (
)
from homeassistant.components.homematicip_cloud.hap import HomematicipHAP
from homeassistant.components.homematicip_cloud.sensor import (
ATTR_ACCELERATION_SENSOR_NEUTRAL_POSITION,
ATTR_ACCELERATION_SENSOR_SECOND_TRIGGER_ANGLE,
ATTR_ACCELERATION_SENSOR_TRIGGER_ANGLE,
ATTR_CURRENT_ILLUMINATION,
ATTR_HIGHEST_ILLUMINATION,
ATTR_LEFT_COUNTER,
@ -708,6 +711,54 @@ async def test_hmip_esi_led_energy_counter_usage_high_tariff(
assert ha_state.state == "23825.748"
async def test_hmip_tilt_vibration_sensor_tilt_state(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipTiltVibrationSensor."""
entity_id = "sensor.neigungssensor_tor_tilt_state"
entity_name = "Neigungssensor Tor Tilt State"
device_model = "ELV-SH-CTV"
mock_hap = await default_mock_hap_factory.async_get_mock_hap(
test_devices=["Neigungssensor Tor"]
)
ha_state, hmip_device = get_and_check_entity_basics(
hass, mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == "neutral"
await async_manipulate_test_data(hass, hmip_device, "tiltState", "NON_NEUTRAL", 1)
ha_state = hass.states.get(entity_id)
assert ha_state.state == "non_neutral"
await async_manipulate_test_data(hass, hmip_device, "tiltState", "TILTED", 1)
ha_state = hass.states.get(entity_id)
assert ha_state.state == "tilted"
assert ha_state.attributes[ATTR_ACCELERATION_SENSOR_NEUTRAL_POSITION] == "VERTICAL"
assert ha_state.attributes[ATTR_ACCELERATION_SENSOR_TRIGGER_ANGLE] == 20
assert ha_state.attributes[ATTR_ACCELERATION_SENSOR_SECOND_TRIGGER_ANGLE] == 75
async def test_hmip_tilt_vibration_sensor_tilt_angle(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipTiltVibrationSensor."""
entity_id = "sensor.neigungssensor_tor_tilt_angle"
entity_name = "Neigungssensor Tor Tilt Angle"
device_model = "ELV-SH-CTV"
mock_hap = await default_mock_hap_factory.async_get_mock_hap(
test_devices=["Neigungssensor Tor"]
)
ha_state, hmip_device = get_and_check_entity_basics(
hass, mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == "89"
async def test_hmip_absolute_humidity_sensor(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None: