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
This commit is contained in:
Guillaume Duveau 2023-07-06 20:26:46 +02:00 committed by GitHub
parent ecc0917e8f
commit 23d5fb9622
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 150 additions and 38 deletions

View File

@ -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

View File

@ -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:

View File

@ -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"

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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: