From 4dee2b599a789a10a84b9ff4eef83341f3fcd379 Mon Sep 17 00:00:00 2001 From: SukramJ Date: Thu, 3 Sep 2020 17:23:42 +0200 Subject: [PATCH] Add HmIP-STV to HomematicIP Cloud (#39518) * add general attribute for connection type * Add HmIP-STV to HomematicIP Cloud --- .../homematicip_cloud/binary_sensor.py | 15 ++++++-- .../homematicip_cloud/generic_entity.py | 2 ++ .../homematicip_cloud/test_binary_sensor.py | 36 +++++++++++++++++++ .../homematicip_cloud/test_device.py | 2 +- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/homematicip_cloud/binary_sensor.py b/homeassistant/components/homematicip_cloud/binary_sensor.py index 15ba9049dba..50e8360675b 100644 --- a/homeassistant/components/homematicip_cloud/binary_sensor.py +++ b/homeassistant/components/homematicip_cloud/binary_sensor.py @@ -16,6 +16,7 @@ from homematicip.aio.device import ( AsyncShutterContact, AsyncShutterContactMagnetic, AsyncSmokeDetector, + AsyncTiltVibrationSensor, AsyncWaterSensor, AsyncWeatherSensor, AsyncWeatherSensorPlus, @@ -85,6 +86,8 @@ async def async_setup_entry( for device in hap.home.devices: if isinstance(device, AsyncAccelerationSensor): entities.append(HomematicipAccelerationSensor(hap, device)) + if isinstance(device, AsyncTiltVibrationSensor): + entities.append(HomematicipTiltVibrationSensor(hap, device)) if isinstance(device, (AsyncContactInterface, AsyncFullFlushContactInterface)): entities.append(HomematicipContactInterface(hap, device)) if isinstance( @@ -133,8 +136,8 @@ async def async_setup_entry( async_add_entities(entities) -class HomematicipAccelerationSensor(HomematicipGenericEntity, BinarySensorEntity): - """Representation of the HomematicIP acceleration sensor.""" +class HomematicipBaseActionSensor(HomematicipGenericEntity, BinarySensorEntity): + """Representation of the HomematicIP base action sensor.""" @property def device_class(self) -> str: @@ -159,6 +162,14 @@ class HomematicipAccelerationSensor(HomematicipGenericEntity, BinarySensorEntity return state_attr +class HomematicipAccelerationSensor(HomematicipBaseActionSensor): + """Representation of the HomematicIP acceleration sensor.""" + + +class HomematicipTiltVibrationSensor(HomematicipBaseActionSensor): + """Representation of the HomematicIP tilt vibration sensor.""" + + class HomematicipContactInterface(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP contact interface.""" diff --git a/homeassistant/components/homematicip_cloud/generic_entity.py b/homeassistant/components/homematicip_cloud/generic_entity.py index 7450a82943f..3a19c1b2afe 100644 --- a/homeassistant/components/homematicip_cloud/generic_entity.py +++ b/homeassistant/components/homematicip_cloud/generic_entity.py @@ -17,6 +17,7 @@ _LOGGER = logging.getLogger(__name__) ATTR_MODEL_TYPE = "model_type" ATTR_LOW_BATTERY = "low_battery" ATTR_CONFIG_PENDING = "config_pending" +ATTR_CONNECTION_TYPE = "connection_type" ATTR_DUTY_CYCLE_REACHED = "duty_cycle_reached" ATTR_ID = "id" ATTR_IS_GROUP = "is_group" @@ -43,6 +44,7 @@ DEVICE_ATTRIBUTE_ICONS = { DEVICE_ATTRIBUTES = { "modelType": ATTR_MODEL_TYPE, + "connectionType": ATTR_CONNECTION_TYPE, "sabotage": ATTR_SABOTAGE, "dutyCycle": ATTR_DUTY_CYCLE_REACHED, "rssiDeviceValue": ATTR_RSSI_DEVICE, diff --git a/tests/components/homematicip_cloud/test_binary_sensor.py b/tests/components/homematicip_cloud/test_binary_sensor.py index 06b19ae0805..f15b2b56a95 100644 --- a/tests/components/homematicip_cloud/test_binary_sensor.py +++ b/tests/components/homematicip_cloud/test_binary_sensor.py @@ -75,6 +75,42 @@ async def test_hmip_acceleration_sensor(hass, default_mock_hap_factory): assert len(hmip_device.mock_calls) == service_call_counter + 2 +async def test_hmip_tilt_vibration_sensor(hass, default_mock_hap_factory): + """Test HomematicipTiltVibrationSensor.""" + entity_id = "binary_sensor.garage_neigungs_und_erschutterungssensor" + entity_name = "Garage Neigungs- und Erschütterungssensor" + device_model = "HmIP-STV" + mock_hap = await default_mock_hap_factory.async_get_mock_hap( + test_devices=[entity_name] + ) + + ha_state, hmip_device = get_and_check_entity_basics( + hass, mock_hap, entity_id, entity_name, device_model + ) + + assert ha_state.state == STATE_ON + assert ha_state.attributes[ATTR_ACCELERATION_SENSOR_MODE] == "FLAT_DECT" + assert ( + ha_state.attributes[ATTR_ACCELERATION_SENSOR_SENSITIVITY] == "SENSOR_RANGE_2G" + ) + assert ha_state.attributes[ATTR_ACCELERATION_SENSOR_TRIGGER_ANGLE] == 45 + service_call_counter = len(hmip_device.mock_calls) + + await async_manipulate_test_data( + hass, hmip_device, "accelerationSensorTriggered", False + ) + ha_state = hass.states.get(entity_id) + assert ha_state.state == STATE_OFF + assert len(hmip_device.mock_calls) == service_call_counter + 1 + + await async_manipulate_test_data( + hass, hmip_device, "accelerationSensorTriggered", True + ) + ha_state = hass.states.get(entity_id) + assert ha_state.state == STATE_ON + assert len(hmip_device.mock_calls) == service_call_counter + 2 + + async def test_hmip_contact_interface(hass, default_mock_hap_factory): """Test HomematicipContactInterface.""" entity_id = "binary_sensor.kontakt_schnittstelle_unterputz_1_fach" diff --git a/tests/components/homematicip_cloud/test_device.py b/tests/components/homematicip_cloud/test_device.py index 0154eb7b327..f7999b5f015 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) == 190 + assert len(mock_hap.hmip_device_by_entity_id) == 191 async def test_hmip_remove_device(hass, default_mock_hap_factory):