From f4e7436421479d902569c919d8e7279812cd9571 Mon Sep 17 00:00:00 2001 From: hahn-th Date: Mon, 25 Jul 2022 18:15:02 +0200 Subject: [PATCH] Add device HmIP-STE2-PCB to homematicip_cloud (#75369) --- .../homematicip_cloud/manifest.json | 2 +- .../components/homematicip_cloud/sensor.py | 80 ++++++++++++++++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../homematicip_cloud/test_device.py | 2 +- .../homematicip_cloud/test_sensor.py | 75 +++++++++++++++ tests/fixtures/homematicip_cloud.json | 94 +++++++++++++++++++ 7 files changed, 253 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/homematicip_cloud/manifest.json b/homeassistant/components/homematicip_cloud/manifest.json index db0833f81148bb..0d06d595f1b545 100644 --- a/homeassistant/components/homematicip_cloud/manifest.json +++ b/homeassistant/components/homematicip_cloud/manifest.json @@ -3,7 +3,7 @@ "name": "HomematicIP Cloud", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/homematicip_cloud", - "requirements": ["homematicip==1.0.5"], + "requirements": ["homematicip==1.0.7"], "codeowners": [], "quality_scale": "platinum", "iot_class": "cloud_push", diff --git a/homeassistant/components/homematicip_cloud/sensor.py b/homeassistant/components/homematicip_cloud/sensor.py index 80cdbd351b1a8d..57a8b7bd714d1c 100644 --- a/homeassistant/components/homematicip_cloud/sensor.py +++ b/homeassistant/components/homematicip_cloud/sensor.py @@ -17,6 +17,7 @@ AsyncPlugableSwitchMeasuring, AsyncPresenceDetectorIndoor, AsyncRoomControlDeviceAnalog, + AsyncTemperatureDifferenceSensor2, AsyncTemperatureHumiditySensorDisplay, AsyncTemperatureHumiditySensorOutdoor, AsyncTemperatureHumiditySensorWithoutDisplay, @@ -124,6 +125,10 @@ async def async_setup_entry( entities.append(HomematicipTodayRainSensor(hap, device)) if isinstance(device, AsyncPassageDetector): entities.append(HomematicipPassageDetectorDeltaCounter(hap, device)) + if isinstance(device, AsyncTemperatureDifferenceSensor2): + entities.append(HomematicpTemperatureExternalSensorCh1(hap, device)) + entities.append(HomematicpTemperatureExternalSensorCh2(hap, device)) + entities.append(HomematicpTemperatureExternalSensorDelta(hap, device)) if entities: async_add_entities(entities) @@ -387,6 +392,81 @@ def native_unit_of_measurement(self) -> str: return LENGTH_MILLIMETERS +class HomematicpTemperatureExternalSensorCh1(HomematicipGenericEntity, SensorEntity): + """Representation of the HomematicIP device HmIP-STE2-PCB.""" + + _attr_state_class = SensorStateClass.MEASUREMENT + + def __init__(self, hap: HomematicipHAP, device) -> None: + """Initialize the device.""" + super().__init__(hap, device, post="Channel 1 Temperature") + + @property + def device_class(self) -> str: + """Return the device class of the sensor.""" + return SensorDeviceClass.TEMPERATURE + + @property + def native_value(self) -> float: + """Return the state.""" + return self._device.temperatureExternalOne + + @property + def native_unit_of_measurement(self) -> str: + """Return the unit this state is expressed in.""" + return TEMP_CELSIUS + + +class HomematicpTemperatureExternalSensorCh2(HomematicipGenericEntity, SensorEntity): + """Representation of the HomematicIP device HmIP-STE2-PCB.""" + + _attr_state_class = SensorStateClass.MEASUREMENT + + def __init__(self, hap: HomematicipHAP, device) -> None: + """Initialize the device.""" + super().__init__(hap, device, post="Channel 2 Temperature") + + @property + def device_class(self) -> str: + """Return the device class of the sensor.""" + return SensorDeviceClass.TEMPERATURE + + @property + def native_value(self) -> float: + """Return the state.""" + return self._device.temperatureExternalTwo + + @property + def native_unit_of_measurement(self) -> str: + """Return the unit this state is expressed in.""" + return TEMP_CELSIUS + + +class HomematicpTemperatureExternalSensorDelta(HomematicipGenericEntity, SensorEntity): + """Representation of the HomematicIP device HmIP-STE2-PCB.""" + + _attr_state_class = SensorStateClass.MEASUREMENT + + def __init__(self, hap: HomematicipHAP, device) -> None: + """Initialize the device.""" + super().__init__(hap, device, post="Delta Temperature") + + @property + def device_class(self) -> str: + """Return the device class of the sensor.""" + return SensorDeviceClass.TEMPERATURE + + @property + def native_value(self) -> float: + """Return the state.""" + return self._device.temperatureExternalDelta + + @property + def native_unit_of_measurement(self) -> str: + """Return the unit this state is expressed in.""" + return TEMP_CELSIUS + + class HomematicipPassageDetectorDeltaCounter(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP passage detector delta counter.""" diff --git a/requirements_all.txt b/requirements_all.txt index 4cdebd91a2afac..b56c176652abf5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -846,7 +846,7 @@ home-assistant-frontend==20220707.1 homeconnect==0.7.1 # homeassistant.components.homematicip_cloud -homematicip==1.0.5 +homematicip==1.0.7 # homeassistant.components.home_plus_control homepluscontrol==0.0.5 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 83afdad8daa264..8e5146bcfc24a3 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -622,7 +622,7 @@ home-assistant-frontend==20220707.1 homeconnect==0.7.1 # homeassistant.components.homematicip_cloud -homematicip==1.0.5 +homematicip==1.0.7 # homeassistant.components.home_plus_control homepluscontrol==0.0.5 diff --git a/tests/components/homematicip_cloud/test_device.py b/tests/components/homematicip_cloud/test_device.py index 8e3d80ca8390ee..44b91c4ed47930 100644 --- a/tests/components/homematicip_cloud/test_device.py +++ b/tests/components/homematicip_cloud/test_device.py @@ -22,7 +22,7 @@ async def test_hmip_load_all_supported_devices(hass, default_mock_hap_factory): test_devices=None, test_groups=None ) - assert len(mock_hap.hmip_device_by_entity_id) == 258 + assert len(mock_hap.hmip_device_by_entity_id) == 262 async def test_hmip_remove_device(hass, default_mock_hap_factory): diff --git a/tests/components/homematicip_cloud/test_sensor.py b/tests/components/homematicip_cloud/test_sensor.py index 34c119595b308c..823508d5feebb1 100644 --- a/tests/components/homematicip_cloud/test_sensor.py +++ b/tests/components/homematicip_cloud/test_sensor.py @@ -340,6 +340,81 @@ async def test_hmip_today_rain_sensor(hass, default_mock_hap_factory): assert ha_state.state == "14.2" +async def test_hmip_temperature_external_sensor_channel_1( + hass, default_mock_hap_factory +): + """Test HomematicipTemperatureDifferenceSensor Channel 1 HmIP-STE2-PCB.""" + entity_id = "sensor.ste2_channel_1_temperature" + entity_name = "STE2 Channel 1 Temperature" + device_model = "HmIP-STE2-PCB" + + mock_hap = await default_mock_hap_factory.async_get_mock_hap(test_devices=["STE2"]) + ha_state, hmip_device = get_and_check_entity_basics( + hass, mock_hap, entity_id, entity_name, device_model + ) + + hmip_device = mock_hap.hmip_device_by_entity_id.get(entity_id) + + await async_manipulate_test_data(hass, hmip_device, "temperatureExternalOne", 25.4) + + ha_state = hass.states.get(entity_id) + assert ha_state.state == "25.4" + assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS + await async_manipulate_test_data(hass, hmip_device, "temperatureExternalOne", 23.5) + ha_state = hass.states.get(entity_id) + assert ha_state.state == "23.5" + + +async def test_hmip_temperature_external_sensor_channel_2( + hass, default_mock_hap_factory +): + """Test HomematicipTemperatureDifferenceSensor Channel 2 HmIP-STE2-PCB.""" + entity_id = "sensor.ste2_channel_2_temperature" + entity_name = "STE2 Channel 2 Temperature" + device_model = "HmIP-STE2-PCB" + + mock_hap = await default_mock_hap_factory.async_get_mock_hap(test_devices=["STE2"]) + ha_state, hmip_device = get_and_check_entity_basics( + hass, mock_hap, entity_id, entity_name, device_model + ) + + hmip_device = mock_hap.hmip_device_by_entity_id.get(entity_id) + + await async_manipulate_test_data(hass, hmip_device, "temperatureExternalTwo", 22.4) + + ha_state = hass.states.get(entity_id) + assert ha_state.state == "22.4" + assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS + await async_manipulate_test_data(hass, hmip_device, "temperatureExternalTwo", 23.4) + ha_state = hass.states.get(entity_id) + assert ha_state.state == "23.4" + + +async def test_hmip_temperature_external_sensor_delta(hass, default_mock_hap_factory): + """Test HomematicipTemperatureDifferenceSensor Delta HmIP-STE2-PCB.""" + entity_id = "sensor.ste2_delta_temperature" + entity_name = "STE2 Delta Temperature" + device_model = "HmIP-STE2-PCB" + + mock_hap = await default_mock_hap_factory.async_get_mock_hap(test_devices=["STE2"]) + ha_state, hmip_device = get_and_check_entity_basics( + hass, mock_hap, entity_id, entity_name, device_model + ) + + hmip_device = mock_hap.hmip_device_by_entity_id.get(entity_id) + + await async_manipulate_test_data(hass, hmip_device, "temperatureExternalDelta", 0.4) + + ha_state = hass.states.get(entity_id) + assert ha_state.state == "0.4" + assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS + await async_manipulate_test_data( + hass, hmip_device, "temperatureExternalDelta", -0.5 + ) + ha_state = hass.states.get(entity_id) + assert ha_state.state == "-0.5" + + async def test_hmip_passage_detector_delta_counter(hass, default_mock_hap_factory): """Test HomematicipPassageDetectorDeltaCounter.""" entity_id = "sensor.spdr_1" diff --git a/tests/fixtures/homematicip_cloud.json b/tests/fixtures/homematicip_cloud.json index 2c125d9fada86a..b0037aa380044c 100644 --- a/tests/fixtures/homematicip_cloud.json +++ b/tests/fixtures/homematicip_cloud.json @@ -6631,6 +6631,100 @@ "serializedGlobalTradeItemNumber": "3014F7110000000000056775", "type": "FULL_FLUSH_CONTACT_INTERFACE_6", "updateState": "UP_TO_DATE" + }, + "3014F7110000000000STE2015": { + "availableFirmwareVersion": "1.0.26", + "connectionType": "HMIP_RF", + "firmwareVersion": "1.0.18", + "firmwareVersionInteger": 65554, + "functionalChannels": { + "0": { + "busConfigMismatch": null, + "coProFaulty": false, + "coProRestartNeeded": false, + "coProUpdateFailure": false, + "configPending": false, + "deviceId": "3014F7110000000000STE2015", + "deviceOverheated": false, + "deviceOverloaded": false, + "devicePowerFailureDetected": false, + "deviceUndervoltage": false, + "displayContrast": null, + "dutyCycle": false, + "functionalChannelType": "DEVICE_BASE", + "groupIndex": 0, + "groups": ["00000000-0000-0000-0000-000000000024"], + "index": 0, + "label": "", + "lockJammed": null, + "lowBat": false, + "mountingOrientation": null, + "multicastRoutingEnabled": false, + "particulateMatterSensorCommunicationError": null, + "particulateMatterSensorError": null, + "powerShortCircuit": null, + "profilePeriodLimitReached": null, + "routerModuleEnabled": false, + "routerModuleSupported": false, + "rssiDeviceValue": -60, + "rssiPeerValue": null, + "shortCircuitDataLine": null, + "supportedOptionalFeatures": { + "IFeatureBusConfigMismatch": false, + "IFeatureDeviceCoProError": false, + "IFeatureDeviceCoProRestart": false, + "IFeatureDeviceCoProUpdate": false, + "IFeatureDeviceIdentify": false, + "IFeatureDeviceOverheated": false, + "IFeatureDeviceOverloaded": false, + "IFeatureDeviceParticulateMatterSensorCommunicationError": false, + "IFeatureDeviceParticulateMatterSensorError": false, + "IFeatureDevicePowerFailure": false, + "IFeatureDeviceTemperatureHumiditySensorCommunicationError": false, + "IFeatureDeviceTemperatureHumiditySensorError": false, + "IFeatureDeviceTemperatureOutOfRange": false, + "IFeatureDeviceUndervoltage": false, + "IFeatureMulticastRouter": false, + "IFeaturePowerShortCircuit": false, + "IFeatureProfilePeriodLimit": false, + "IFeatureRssiValue": true, + "IFeatureShortCircuitDataLine": false, + "IOptionalFeatureDeviceErrorLockJammed": false, + "IOptionalFeatureDisplayContrast": false, + "IOptionalFeatureDutyCycle": true, + "IOptionalFeatureLowBat": true, + "IOptionalFeatureMountingOrientation": false + }, + "temperatureHumiditySensorCommunicationError": null, + "temperatureHumiditySensorError": null, + "temperatureOutOfRange": false, + "unreach": false + }, + "1": { + "deviceId": "3014F7110000000000STE2015", + "functionalChannelType": "TEMPERATURE_SENSOR_2_EXTERNAL_DELTA_CHANNEL", + "groupIndex": 1, + "groups": ["00000000-0000-0000-0000-000000000025"], + "index": 1, + "label": "", + "temperatureExternalDelta": -0.9, + "temperatureExternalOne": 24.5, + "temperatureExternalTwo": 25.4 + } + }, + "homeId": "00000000-0000-0000-0000-000000000001", + "id": "3014F7110000000000STE2015", + "label": "STE2", + "lastStatusUpdate": 1645012379988, + "liveUpdateState": "LIVE_UPDATE_NOT_SUPPORTED", + "manufacturerCode": 1, + "modelId": 415, + "modelType": "HmIP-STE2-PCB", + "oem": "eQ-3", + "permanentlyReachable": false, + "serializedGlobalTradeItemNumber": "3014F7110000000000STE2015", + "type": "TEMPERATURE_SENSOR_2_EXTERNAL_DELTA", + "updateState": "TRANSFERING_UPDATE" } }, "groups": {