mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Bump pysmartthings to 2.0.0 (#139418)
* Bump pysmartthings to 2.0.0 * Fix * Fix * Fix * Fix
This commit is contained in:
parent
0c08430507
commit
2cde317d59
@ -46,7 +46,7 @@ class FullDevice:
|
|||||||
"""Define an object to hold device data."""
|
"""Define an object to hold device data."""
|
||||||
|
|
||||||
device: Device
|
device: Device
|
||||||
status: dict[str, dict[Capability, dict[Attribute, Status]]]
|
status: dict[str, dict[Capability | str, dict[Attribute | str, Status]]]
|
||||||
|
|
||||||
|
|
||||||
type SmartThingsConfigEntry = ConfigEntry[SmartThingsData]
|
type SmartThingsConfigEntry = ConfigEntry[SmartThingsData]
|
||||||
@ -146,8 +146,8 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def process_status(
|
def process_status(
|
||||||
status: dict[str, dict[Capability, dict[Attribute, Status]]],
|
status: dict[str, dict[Capability | str, dict[Attribute | str, Status]]],
|
||||||
) -> dict[str, dict[Capability, dict[Attribute, Status]]]:
|
) -> dict[str, dict[Capability | str, dict[Attribute | str, Status]]]:
|
||||||
"""Remove disabled capabilities from status."""
|
"""Remove disabled capabilities from status."""
|
||||||
if (main_component := status.get("main")) is None or (
|
if (main_component := status.get("main")) is None or (
|
||||||
disabled_capabilities_capability := main_component.get(
|
disabled_capabilities_capability := main_component.get(
|
||||||
@ -156,7 +156,7 @@ def process_status(
|
|||||||
) is None:
|
) is None:
|
||||||
return status
|
return status
|
||||||
disabled_capabilities = cast(
|
disabled_capabilities = cast(
|
||||||
list[Capability],
|
list[Capability | str],
|
||||||
disabled_capabilities_capability[Attribute.DISABLED_CAPABILITIES].value,
|
disabled_capabilities_capability[Attribute.DISABLED_CAPABILITIES].value,
|
||||||
)
|
)
|
||||||
for capability in disabled_capabilities:
|
for capability in disabled_capabilities:
|
||||||
|
@ -41,7 +41,7 @@ async def async_setup_entry(
|
|||||||
"""Add covers for a config entry."""
|
"""Add covers for a config entry."""
|
||||||
entry_data = entry.runtime_data
|
entry_data = entry.runtime_data
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
SmartThingsCover(entry_data.client, device, capability)
|
SmartThingsCover(entry_data.client, device, Capability(capability))
|
||||||
for device in entry_data.devices.values()
|
for device in entry_data.devices.values()
|
||||||
for capability in device.status[MAIN]
|
for capability in device.status[MAIN]
|
||||||
if capability in CAPABILITIES
|
if capability in CAPABILITIES
|
||||||
|
@ -4,7 +4,14 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from pysmartthings import Attribute, Capability, Command, DeviceEvent, SmartThings
|
from pysmartthings import (
|
||||||
|
Attribute,
|
||||||
|
Capability,
|
||||||
|
Command,
|
||||||
|
DeviceEvent,
|
||||||
|
SmartThings,
|
||||||
|
Status,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
@ -25,7 +32,7 @@ class SmartThingsEntity(Entity):
|
|||||||
"""Initialize the instance."""
|
"""Initialize the instance."""
|
||||||
self.client = client
|
self.client = client
|
||||||
self.capabilities = capabilities
|
self.capabilities = capabilities
|
||||||
self._internal_state = {
|
self._internal_state: dict[Capability | str, dict[Attribute | str, Status]] = {
|
||||||
capability: device.status[MAIN][capability]
|
capability: device.status[MAIN][capability]
|
||||||
for capability in capabilities
|
for capability in capabilities
|
||||||
if capability in device.status[MAIN]
|
if capability in device.status[MAIN]
|
||||||
@ -58,7 +65,7 @@ class SmartThingsEntity(Entity):
|
|||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
for capability in self._internal_state:
|
for capability in self._internal_state:
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
self.client.add_device_event_listener(
|
self.client.add_device_capability_event_listener(
|
||||||
self.device.device.device_id,
|
self.device.device.device_id,
|
||||||
MAIN,
|
MAIN,
|
||||||
capability,
|
capability,
|
||||||
|
@ -29,5 +29,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/smartthings",
|
"documentation": "https://www.home-assistant.io/integrations/smartthings",
|
||||||
"iot_class": "cloud_push",
|
"iot_class": "cloud_push",
|
||||||
"loggers": ["pysmartthings"],
|
"loggers": ["pysmartthings"],
|
||||||
"requirements": ["pysmartthings==1.2.0"]
|
"requirements": ["pysmartthings==2.0.0"]
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,7 @@ class SmartThingsSensorEntityDescription(SensorEntityDescription):
|
|||||||
unique_id_separator: str = "."
|
unique_id_separator: str = "."
|
||||||
capability_ignore_list: list[set[Capability]] | None = None
|
capability_ignore_list: list[set[Capability]] | None = None
|
||||||
options_attribute: Attribute | None = None
|
options_attribute: Attribute | None = None
|
||||||
|
except_if_state_none: bool = False
|
||||||
|
|
||||||
|
|
||||||
CAPABILITY_TO_SENSORS: dict[
|
CAPABILITY_TO_SENSORS: dict[
|
||||||
@ -579,6 +580,7 @@ CAPABILITY_TO_SENSORS: dict[
|
|||||||
device_class=SensorDeviceClass.ENERGY,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
value_fn=lambda value: value["energy"] / 1000,
|
value_fn=lambda value: value["energy"] / 1000,
|
||||||
|
except_if_state_none=True,
|
||||||
),
|
),
|
||||||
SmartThingsSensorEntityDescription(
|
SmartThingsSensorEntityDescription(
|
||||||
key="power_meter",
|
key="power_meter",
|
||||||
@ -587,6 +589,7 @@ CAPABILITY_TO_SENSORS: dict[
|
|||||||
native_unit_of_measurement=UnitOfPower.WATT,
|
native_unit_of_measurement=UnitOfPower.WATT,
|
||||||
value_fn=lambda value: value["power"],
|
value_fn=lambda value: value["power"],
|
||||||
extra_state_attributes_fn=power_attributes,
|
extra_state_attributes_fn=power_attributes,
|
||||||
|
except_if_state_none=True,
|
||||||
),
|
),
|
||||||
SmartThingsSensorEntityDescription(
|
SmartThingsSensorEntityDescription(
|
||||||
key="deltaEnergy_meter",
|
key="deltaEnergy_meter",
|
||||||
@ -595,6 +598,7 @@ CAPABILITY_TO_SENSORS: dict[
|
|||||||
device_class=SensorDeviceClass.ENERGY,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
value_fn=lambda value: value["deltaEnergy"] / 1000,
|
value_fn=lambda value: value["deltaEnergy"] / 1000,
|
||||||
|
except_if_state_none=True,
|
||||||
),
|
),
|
||||||
SmartThingsSensorEntityDescription(
|
SmartThingsSensorEntityDescription(
|
||||||
key="powerEnergy_meter",
|
key="powerEnergy_meter",
|
||||||
@ -603,6 +607,7 @@ CAPABILITY_TO_SENSORS: dict[
|
|||||||
device_class=SensorDeviceClass.ENERGY,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
value_fn=lambda value: value["powerEnergy"] / 1000,
|
value_fn=lambda value: value["powerEnergy"] / 1000,
|
||||||
|
except_if_state_none=True,
|
||||||
),
|
),
|
||||||
SmartThingsSensorEntityDescription(
|
SmartThingsSensorEntityDescription(
|
||||||
key="energySaved_meter",
|
key="energySaved_meter",
|
||||||
@ -611,6 +616,7 @@ CAPABILITY_TO_SENSORS: dict[
|
|||||||
device_class=SensorDeviceClass.ENERGY,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
value_fn=lambda value: value["energySaved"] / 1000,
|
value_fn=lambda value: value["energySaved"] / 1000,
|
||||||
|
except_if_state_none=True,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -953,16 +959,22 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
SmartThingsSensor(entry_data.client, device, description, capability, attribute)
|
SmartThingsSensor(entry_data.client, device, description, capability, attribute)
|
||||||
for device in entry_data.devices.values()
|
for device in entry_data.devices.values()
|
||||||
for capability, attributes in device.status[MAIN].items()
|
for capability, attributes in CAPABILITY_TO_SENSORS.items()
|
||||||
if capability in CAPABILITY_TO_SENSORS
|
if capability in device.status[MAIN]
|
||||||
for attribute in attributes
|
for attribute, descriptions in attributes.items()
|
||||||
for description in CAPABILITY_TO_SENSORS[capability].get(attribute, [])
|
for description in descriptions
|
||||||
if not description.capability_ignore_list
|
if (
|
||||||
|
not description.capability_ignore_list
|
||||||
or not any(
|
or not any(
|
||||||
all(capability in device.status[MAIN] for capability in capability_list)
|
all(capability in device.status[MAIN] for capability in capability_list)
|
||||||
for capability_list in description.capability_ignore_list
|
for capability_list in description.capability_ignore_list
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
and (
|
||||||
|
not description.except_if_state_none
|
||||||
|
or device.status[MAIN][capability][attribute].value is not None
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SmartThingsSensor(SmartThingsEntity, SensorEntity):
|
class SmartThingsSensor(SmartThingsEntity, SensorEntity):
|
||||||
|
2
requirements_all.txt
generated
2
requirements_all.txt
generated
@ -2310,7 +2310,7 @@ pysma==0.7.5
|
|||||||
pysmappee==0.2.29
|
pysmappee==0.2.29
|
||||||
|
|
||||||
# homeassistant.components.smartthings
|
# homeassistant.components.smartthings
|
||||||
pysmartthings==1.2.0
|
pysmartthings==2.0.0
|
||||||
|
|
||||||
# homeassistant.components.smarty
|
# homeassistant.components.smarty
|
||||||
pysmarty2==0.10.2
|
pysmarty2==0.10.2
|
||||||
|
2
requirements_test_all.txt
generated
2
requirements_test_all.txt
generated
@ -1882,7 +1882,7 @@ pysma==0.7.5
|
|||||||
pysmappee==0.2.29
|
pysmappee==0.2.29
|
||||||
|
|
||||||
# homeassistant.components.smartthings
|
# homeassistant.components.smartthings
|
||||||
pysmartthings==1.2.0
|
pysmartthings==2.0.0
|
||||||
|
|
||||||
# homeassistant.components.smarty
|
# homeassistant.components.smarty
|
||||||
pysmarty2==0.10.2
|
pysmarty2==0.10.2
|
||||||
|
@ -57,7 +57,7 @@ async def trigger_update(
|
|||||||
data: dict[str, Any] | None = None,
|
data: dict[str, Any] | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Trigger an update."""
|
"""Trigger an update."""
|
||||||
for call in mock.add_device_event_listener.call_args_list:
|
for call in mock.add_device_capability_event_listener.call_args_list:
|
||||||
if call[0][0] == device_id and call[0][2] == capability:
|
if call[0][0] == device_id and call[0][2] == capability:
|
||||||
call[0][3](
|
call[0][3](
|
||||||
DeviceEvent(
|
DeviceEvent(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
# name: test_all_entities[aeotec_home_energy_meter_gen5][sensor.aeotec_energy_monitor_energy_2-entry]
|
# name: test_all_entities[aeotec_home_energy_meter_gen5][sensor.aeotec_energy_monitor_energy-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
@ -14,7 +14,7 @@
|
|||||||
'disabled_by': None,
|
'disabled_by': None,
|
||||||
'domain': 'sensor',
|
'domain': 'sensor',
|
||||||
'entity_category': None,
|
'entity_category': None,
|
||||||
'entity_id': 'sensor.aeotec_energy_monitor_energy_2',
|
'entity_id': 'sensor.aeotec_energy_monitor_energy',
|
||||||
'has_entity_name': True,
|
'has_entity_name': True,
|
||||||
'hidden_by': None,
|
'hidden_by': None,
|
||||||
'icon': None,
|
'icon': None,
|
||||||
@ -35,7 +35,7 @@
|
|||||||
'unit_of_measurement': 'kWh',
|
'unit_of_measurement': 'kWh',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[aeotec_home_energy_meter_gen5][sensor.aeotec_energy_monitor_energy_2-state]
|
# name: test_all_entities[aeotec_home_energy_meter_gen5][sensor.aeotec_energy_monitor_energy-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
@ -44,7 +44,7 @@
|
|||||||
'unit_of_measurement': 'kWh',
|
'unit_of_measurement': 'kWh',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.aeotec_energy_monitor_energy_2',
|
'entity_id': 'sensor.aeotec_energy_monitor_energy',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
|
@ -28,7 +28,7 @@ async def test_all_entities(
|
|||||||
snapshot_smartthings_entities(hass, entity_registry, snapshot, Platform.SENSOR)
|
snapshot_smartthings_entities(hass, entity_registry, snapshot, Platform.SENSOR)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("device_fixture", ["aeotec_home_energy_meter_gen5"])
|
@pytest.mark.parametrize("device_fixture", ["da_ac_rac_000001"])
|
||||||
async def test_state_update(
|
async def test_state_update(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
devices: AsyncMock,
|
devices: AsyncMock,
|
||||||
@ -37,15 +37,15 @@ async def test_state_update(
|
|||||||
"""Test state update."""
|
"""Test state update."""
|
||||||
await setup_integration(hass, mock_config_entry)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
assert hass.states.get("sensor.aeotec_energy_monitor_energy_2").state == "19978.536"
|
assert hass.states.get("sensor.ac_office_granit_temperature").state == "25"
|
||||||
|
|
||||||
await trigger_update(
|
await trigger_update(
|
||||||
hass,
|
hass,
|
||||||
devices,
|
devices,
|
||||||
"f0af21a2-d5a1-437c-b10a-b34a87394b71",
|
"96a5ef74-5832-a84b-f1f7-ca799957065d",
|
||||||
Capability.ENERGY_METER,
|
Capability.TEMPERATURE_MEASUREMENT,
|
||||||
Attribute.ENERGY,
|
Attribute.TEMPERATURE,
|
||||||
20000.0,
|
20,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert hass.states.get("sensor.aeotec_energy_monitor_energy_2").state == "20000.0"
|
assert hass.states.get("sensor.ac_office_granit_temperature").state == "20"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user