diff --git a/homeassistant/components/fibaro/__init__.py b/homeassistant/components/fibaro/__init__.py index d9e7e022aee..18b9f46eb20 100644 --- a/homeassistant/components/fibaro/__init__.py +++ b/homeassistant/components/fibaro/__init__.py @@ -241,11 +241,14 @@ class FibaroController: platform = Platform.LOCK elif device.has_central_scene_event: platform = Platform.EVENT - elif device.value.has_value: - if device.value.is_bool_value: - platform = Platform.BINARY_SENSOR - else: - platform = Platform.SENSOR + elif device.value.has_value and device.value.is_bool_value: + platform = Platform.BINARY_SENSOR + elif ( + device.value.has_value + or "power" in device.properties + or "energy" in device.properties + ): + platform = Platform.SENSOR # Switches that control lights should show up as lights if platform == Platform.SWITCH and device.properties.get("isLight", False): diff --git a/homeassistant/components/fibaro/sensor.py b/homeassistant/components/fibaro/sensor.py index 008395b020f..da94cde9ead 100644 --- a/homeassistant/components/fibaro/sensor.py +++ b/homeassistant/components/fibaro/sensor.py @@ -112,6 +112,11 @@ async def async_setup_entry( entities: list[SensorEntity] = [ FibaroSensor(device, MAIN_SENSOR_TYPES.get(device.type)) for device in controller.fibaro_devices[Platform.SENSOR] + # Some sensor devices do not have a value but report power or energy. + # These sensors are added to the sensor list but need to be excluded + # here as the FibaroSensor expects a value. One example is the + # Qubino 3 phase power meter. + if device.value.has_value ] entities.extend( diff --git a/tests/components/fibaro/conftest.py b/tests/components/fibaro/conftest.py index 4d99dea6682..df8b12e2167 100644 --- a/tests/components/fibaro/conftest.py +++ b/tests/components/fibaro/conftest.py @@ -49,6 +49,33 @@ def mock_room() -> Mock: return room +@pytest.fixture +def mock_power_sensor() -> Mock: + """Fixture for an individual power sensor without value.""" + sensor = Mock() + sensor.fibaro_id = 1 + sensor.parent_fibaro_id = 0 + sensor.name = "Test sensor" + sensor.room_id = 1 + sensor.visible = True + sensor.enabled = True + sensor.type = "com.fibaro.powerMeter" + sensor.base_type = "com.fibaro.device" + sensor.properties = { + "zwaveCompany": "Goap", + "endPointId": "2", + "manufacturer": "", + "power": "6.60", + } + sensor.actions = {} + sensor.has_central_scene_event = False + value_mock = Mock() + value_mock.has_value = False + value_mock.is_bool_value = False + sensor.value = value_mock + return sensor + + @pytest.fixture def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry: """Return the default mocked config entry.""" diff --git a/tests/components/fibaro/test_sensor.py b/tests/components/fibaro/test_sensor.py new file mode 100644 index 00000000000..38cbd5d12a8 --- /dev/null +++ b/tests/components/fibaro/test_sensor.py @@ -0,0 +1,39 @@ +"""Test the Fibaro sensor platform.""" + +from unittest.mock import Mock, patch + +from homeassistant.components.sensor import SensorDeviceClass +from homeassistant.const import Platform +from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er + +from .conftest import init_integration + +from tests.common import MockConfigEntry + + +async def test_power_sensor_detected( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_fibaro_client: Mock, + mock_config_entry: MockConfigEntry, + mock_power_sensor: Mock, + mock_room: Mock, +) -> None: + """Test that the strange power entity is detected. + + Similar to a Qubino 3-Phase power meter. + """ + # Arrange + mock_fibaro_client.read_rooms.return_value = [mock_room] + mock_fibaro_client.read_devices.return_value = [mock_power_sensor] + + with patch("homeassistant.components.fibaro.PLATFORMS", [Platform.SENSOR]): + # Act + await init_integration(hass, mock_config_entry) + # Assert + entry = entity_registry.async_get("sensor.room_1_test_sensor_1_power") + assert entry + assert entry.unique_id == "hc2_111111.1_power" + assert entry.original_name == "Room 1 Test sensor Power" + assert entry.original_device_class == SensorDeviceClass.POWER