diff --git a/homeassistant/components/homematicip_cloud/binary_sensor.py b/homeassistant/components/homematicip_cloud/binary_sensor.py index 50e8360675b..440dc31788f 100644 --- a/homeassistant/components/homematicip_cloud/binary_sensor.py +++ b/homeassistant/components/homematicip_cloud/binary_sensor.py @@ -82,7 +82,7 @@ async def async_setup_entry( ) -> None: """Set up the HomematicIP Cloud binary sensor from a config entry.""" hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id] - entities = [] + entities = [HomematicipCloudConnectionSensor(hap)] for device in hap.home.devices: if isinstance(device, AsyncAccelerationSensor): entities.append(HomematicipAccelerationSensor(hap, device)) @@ -136,6 +136,44 @@ async def async_setup_entry( async_add_entities(entities) +class HomematicipCloudConnectionSensor(HomematicipGenericEntity, BinarySensorEntity): + """Representation of the HomematicIP cloud connection sensor.""" + + def __init__(self, hap: HomematicipHAP) -> None: + """Initialize the cloud connection sensor.""" + super().__init__(hap, hap.home, "Cloud Connection") + + @property + def device_info(self) -> Dict[str, Any]: + """Return device specific attributes.""" + # Adds a sensor to the existing HAP device + return { + "identifiers": { + # Serial numbers of Homematic IP device + (HMIPC_DOMAIN, self._home.id) + } + } + + @property + def icon(self) -> str: + """Return the icon of the access point entity.""" + return ( + "mdi:access-point-network" + if self._home.connected + else "mdi:access-point-network-off" + ) + + @property + def is_on(self) -> bool: + """Return true if hap is connected to cloud.""" + return self._home.connected + + @property + def available(self) -> bool: + """Sensor is always available.""" + return True + + class HomematicipBaseActionSensor(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP base action sensor.""" diff --git a/homeassistant/components/homematicip_cloud/sensor.py b/homeassistant/components/homematicip_cloud/sensor.py index 32191cde20e..86881f565ce 100644 --- a/homeassistant/components/homematicip_cloud/sensor.py +++ b/homeassistant/components/homematicip_cloud/sensor.py @@ -125,7 +125,7 @@ class HomematicipAccesspointStatus(HomematicipGenericEntity): def __init__(self, hap: HomematicipHAP) -> None: """Initialize access point status entity.""" - super().__init__(hap, hap.home) + super().__init__(hap, hap.home, "Duty Cycle") @property def device_info(self) -> Dict[str, Any]: @@ -134,7 +134,7 @@ class HomematicipAccesspointStatus(HomematicipGenericEntity): return { "identifiers": { # Serial numbers of Homematic IP device - (HMIPC_DOMAIN, self._device.id) + (HMIPC_DOMAIN, self._home.id) } } diff --git a/tests/components/homematicip_cloud/test_binary_sensor.py b/tests/components/homematicip_cloud/test_binary_sensor.py index f15b2b56a95..6d6ba84e243 100644 --- a/tests/components/homematicip_cloud/test_binary_sensor.py +++ b/tests/components/homematicip_cloud/test_binary_sensor.py @@ -38,6 +38,29 @@ async def test_manually_configured_platform(hass): assert not hass.data.get(HMIPC_DOMAIN) +async def test_hmip_access_point_cloud_connection_sensor( + hass, default_mock_hap_factory +): + """Test HomematicipCloudConnectionSensor.""" + entity_id = "binary_sensor.access_point_cloud_connection" + entity_name = "Access Point Cloud Connection" + device_model = None + 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 + + await async_manipulate_test_data(hass, hmip_device, "connected", False) + + ha_state = hass.states.get(entity_id) + assert ha_state.state == STATE_OFF + + async def test_hmip_acceleration_sensor(hass, default_mock_hap_factory): """Test HomematicipAccelerationSensor.""" entity_id = "binary_sensor.garagentor" diff --git a/tests/components/homematicip_cloud/test_device.py b/tests/components/homematicip_cloud/test_device.py index f7999b5f015..c47f0bf25ea 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) == 191 + assert len(mock_hap.hmip_device_by_entity_id) == 192 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 fe7283b471e..55d1e32bf2b 100644 --- a/tests/components/homematicip_cloud/test_sensor.py +++ b/tests/components/homematicip_cloud/test_sensor.py @@ -44,8 +44,8 @@ async def test_manually_configured_platform(hass): async def test_hmip_accesspoint_status(hass, default_mock_hap_factory): """Test HomematicipSwitch.""" - entity_id = "sensor.access_point" - entity_name = "Access Point" + entity_id = "sensor.access_point_duty_cycle" + entity_name = "Access Point Duty Cycle" device_model = None mock_hap = await default_mock_hap_factory.async_get_mock_hap( test_devices=[entity_name]