From 23d5fb962211f95cce9dc34458fa321752399b82 Mon Sep 17 00:00:00 2001 From: Guillaume Duveau Date: Thu, 6 Jul 2023 20:26:46 +0200 Subject: [PATCH] Add more device info for SmartThings devices (#95723) * Add more device info for SmartThings devices * Fix binary_sensor test * Fix binary sensor test, try 2 * Fix and add SmartsThings new device info tests --- .../components/smartthings/__init__.py | 6 +- .../smartthings/test_binary_sensor.py | 16 ++++- tests/components/smartthings/test_climate.py | 10 ++- tests/components/smartthings/test_cover.py | 16 ++++- tests/components/smartthings/test_fan.py | 15 +++- tests/components/smartthings/test_light.py | 17 ++++- tests/components/smartthings/test_lock.py | 18 ++++- tests/components/smartthings/test_sensor.py | 72 ++++++++++++++----- tests/components/smartthings/test_switch.py | 18 ++++- 9 files changed, 150 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/smartthings/__init__.py b/homeassistant/components/smartthings/__init__.py index 024f04b0dc9..6606352ffc8 100644 --- a/homeassistant/components/smartthings/__init__.py +++ b/homeassistant/components/smartthings/__init__.py @@ -452,9 +452,11 @@ class SmartThingsEntity(Entity): return DeviceInfo( configuration_url="https://account.smartthings.com", identifiers={(DOMAIN, self._device.device_id)}, - manufacturer="Unavailable", - model=self._device.device_type_name, + manufacturer=self._device.status.ocf_manufacturer_name, + model=self._device.status.ocf_model_number, name=self._device.label, + hw_version=self._device.status.ocf_hardware_version, + sw_version=self._device.status.ocf_firmware_version, ) @property diff --git a/tests/components/smartthings/test_binary_sensor.py b/tests/components/smartthings/test_binary_sensor.py index 0b697786b18..b6f2159ae13 100644 --- a/tests/components/smartthings/test_binary_sensor.py +++ b/tests/components/smartthings/test_binary_sensor.py @@ -51,7 +51,15 @@ async def test_entity_and_device_attributes( """Test the attributes of the entity are correct.""" # Arrange device = device_factory( - "Motion Sensor 1", [Capability.motion_sensor], {Attribute.motion: "inactive"} + "Motion Sensor 1", + [Capability.motion_sensor], + { + Attribute.motion: "inactive", + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", + }, ) entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) @@ -66,8 +74,10 @@ async def test_entity_and_device_attributes( assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" async def test_update_from_signal(hass: HomeAssistant, device_factory) -> None: diff --git a/tests/components/smartthings/test_climate.py b/tests/components/smartthings/test_climate.py index 02f6af46655..fe917504dcd 100644 --- a/tests/components/smartthings/test_climate.py +++ b/tests/components/smartthings/test_climate.py @@ -112,6 +112,10 @@ def thermostat_fixture(device_factory): ], Attribute.thermostat_operating_state: "idle", Attribute.humidity: 34, + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", }, ) device.status.attributes[Attribute.temperature] = Status(70, "F", None) @@ -581,5 +585,7 @@ async def test_entity_and_device_attributes(hass: HomeAssistant, thermostat) -> assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, thermostat.device_id)} assert entry.name == thermostat.label - assert entry.model == thermostat.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" diff --git a/tests/components/smartthings/test_cover.py b/tests/components/smartthings/test_cover.py index 715f26beaa7..f8c21166fe1 100644 --- a/tests/components/smartthings/test_cover.py +++ b/tests/components/smartthings/test_cover.py @@ -33,7 +33,15 @@ async def test_entity_and_device_attributes( """Test the attributes of the entity are correct.""" # Arrange device = device_factory( - "Garage", [Capability.garage_door_control], {Attribute.door: "open"} + "Garage", + [Capability.garage_door_control], + { + Attribute.door: "open", + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", + }, ) entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) @@ -49,8 +57,10 @@ async def test_entity_and_device_attributes( assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" async def test_open(hass: HomeAssistant, device_factory) -> None: diff --git a/tests/components/smartthings/test_fan.py b/tests/components/smartthings/test_fan.py index 120a90fb2f4..aef9ce319e7 100644 --- a/tests/components/smartthings/test_fan.py +++ b/tests/components/smartthings/test_fan.py @@ -48,7 +48,14 @@ async def test_entity_and_device_attributes( device = device_factory( "Fan 1", capabilities=[Capability.switch, Capability.fan_speed], - status={Attribute.switch: "on", Attribute.fan_speed: 2}, + status={ + Attribute.switch: "on", + Attribute.fan_speed: 2, + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", + }, ) # Act await setup_platform(hass, FAN_DOMAIN, devices=[device]) @@ -64,8 +71,10 @@ async def test_entity_and_device_attributes( assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" async def test_turn_off(hass: HomeAssistant, device_factory) -> None: diff --git a/tests/components/smartthings/test_light.py b/tests/components/smartthings/test_light.py index 713b156fc4f..0e01910c84a 100644 --- a/tests/components/smartthings/test_light.py +++ b/tests/components/smartthings/test_light.py @@ -109,7 +109,16 @@ async def test_entity_and_device_attributes( ) -> None: """Test the attributes of the entity are correct.""" # Arrange - device = device_factory("Light 1", [Capability.switch, Capability.switch_level]) + device = device_factory( + "Light 1", + [Capability.switch, Capability.switch_level], + { + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", + }, + ) entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) # Act @@ -124,8 +133,10 @@ async def test_entity_and_device_attributes( assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" async def test_turn_off(hass: HomeAssistant, light_devices) -> None: diff --git a/tests/components/smartthings/test_lock.py b/tests/components/smartthings/test_lock.py index 6c01bc2b6c4..0d237cec132 100644 --- a/tests/components/smartthings/test_lock.py +++ b/tests/components/smartthings/test_lock.py @@ -22,7 +22,17 @@ async def test_entity_and_device_attributes( ) -> None: """Test the attributes of the entity are correct.""" # Arrange - device = device_factory("Lock_1", [Capability.lock], {Attribute.lock: "unlocked"}) + device = device_factory( + "Lock_1", + [Capability.lock], + { + Attribute.lock: "unlocked", + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", + }, + ) entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) # Act @@ -37,8 +47,10 @@ async def test_entity_and_device_attributes( assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" async def test_lock(hass: HomeAssistant, device_factory) -> None: diff --git a/tests/components/smartthings/test_sensor.py b/tests/components/smartthings/test_sensor.py index 01745878bf0..cc7b67145c1 100644 --- a/tests/components/smartthings/test_sensor.py +++ b/tests/components/smartthings/test_sensor.py @@ -90,7 +90,17 @@ async def test_entity_and_device_attributes( ) -> None: """Test the attributes of the entity are correct.""" # Arrange - device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100}) + device = device_factory( + "Sensor 1", + [Capability.battery], + { + Attribute.battery: 100, + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", + }, + ) entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) # Act @@ -105,8 +115,10 @@ async def test_entity_and_device_attributes( assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" async def test_energy_sensors_for_switch_device( @@ -117,7 +129,15 @@ async def test_energy_sensors_for_switch_device( device = device_factory( "Switch_1", [Capability.switch, Capability.power_meter, Capability.energy_meter], - {Attribute.switch: "off", Attribute.power: 355, Attribute.energy: 11.422}, + { + Attribute.switch: "off", + Attribute.power: 355, + Attribute.energy: 11.422, + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", + }, ) entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) @@ -136,8 +156,10 @@ async def test_energy_sensors_for_switch_device( assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" state = hass.states.get("sensor.switch_1_power_meter") assert state @@ -151,8 +173,10 @@ async def test_energy_sensors_for_switch_device( assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" async def test_power_consumption_sensor(hass: HomeAssistant, device_factory) -> None: @@ -171,7 +195,11 @@ async def test_power_consumption_sensor(hass: HomeAssistant, device_factory) -> "energySaved": 0, "start": "2021-07-30T16:45:25Z", "end": "2021-07-30T16:58:33Z", - } + }, + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", }, ) entity_registry = er.async_get(hass) @@ -190,8 +218,10 @@ async def test_power_consumption_sensor(hass: HomeAssistant, device_factory) -> assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" state = hass.states.get("sensor.refrigerator_power") assert state @@ -206,13 +236,21 @@ async def test_power_consumption_sensor(hass: HomeAssistant, device_factory) -> assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" device = device_factory( "vacuum", [Capability.power_consumption_report], - {Attribute.power_consumption: {}}, + { + Attribute.power_consumption: {}, + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", + }, ) entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) @@ -230,8 +268,10 @@ async def test_power_consumption_sensor(hass: HomeAssistant, device_factory) -> assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" async def test_update_from_signal(hass: HomeAssistant, device_factory) -> None: diff --git a/tests/components/smartthings/test_switch.py b/tests/components/smartthings/test_switch.py index 81bb8579cfd..f90395f0064 100644 --- a/tests/components/smartthings/test_switch.py +++ b/tests/components/smartthings/test_switch.py @@ -21,7 +21,17 @@ async def test_entity_and_device_attributes( ) -> None: """Test the attributes of the entity are correct.""" # Arrange - device = device_factory("Switch_1", [Capability.switch], {Attribute.switch: "on"}) + device = device_factory( + "Switch_1", + [Capability.switch], + { + Attribute.switch: "on", + Attribute.mnmo: "123", + Attribute.mnmn: "Generic manufacturer", + Attribute.mnhw: "v4.56", + Attribute.mnfv: "v7.89", + }, + ) entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) # Act @@ -36,8 +46,10 @@ async def test_entity_and_device_attributes( assert entry.configuration_url == "https://account.smartthings.com" assert entry.identifiers == {(DOMAIN, device.device_id)} assert entry.name == device.label - assert entry.model == device.device_type_name - assert entry.manufacturer == "Unavailable" + assert entry.model == "123" + assert entry.manufacturer == "Generic manufacturer" + assert entry.hw_version == "v4.56" + assert entry.sw_version == "v7.89" async def test_turn_off(hass: HomeAssistant, device_factory) -> None: