Bump pysmartthings to 3.0.0 (#141058)

* Bump pysmartthings to 2.7.5

* Bump to pysmartthings 3.0.0
This commit is contained in:
Joost Lekkerkerker 2025-03-25 08:37:32 +01:00 committed by GitHub
parent ee3b31c01f
commit 11877a3b12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 32 additions and 24 deletions

View File

@ -3,6 +3,7 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
import contextlib
from dataclasses import dataclass from dataclasses import dataclass
from http import HTTPStatus from http import HTTPStatus
import logging import logging
@ -12,15 +13,17 @@ from aiohttp import ClientResponseError
from pysmartthings import ( from pysmartthings import (
Attribute, Attribute,
Capability, Capability,
ComponentStatus,
Device, Device,
DeviceEvent, DeviceEvent,
Lifecycle,
Scene, Scene,
SmartThings, SmartThings,
SmartThingsAuthenticationFailedError, SmartThingsAuthenticationFailedError,
SmartThingsConnectionError,
SmartThingsSinkError, SmartThingsSinkError,
Status, Status,
) )
from pysmartthings.models import Lifecycle
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -72,7 +75,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 | str, dict[Attribute | str, Status]]] status: dict[str, ComponentStatus]
type SmartThingsConfigEntry = ConfigEntry[SmartThingsData] type SmartThingsConfigEntry = ConfigEntry[SmartThingsData]
@ -124,7 +127,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: SmartThingsConfigEntry)
client.refresh_token_function = _refresh_token client.refresh_token_function = _refresh_token
def _handle_max_connections() -> None: def _handle_max_connections() -> None:
_LOGGER.debug("We hit the limit of max connections") _LOGGER.debug(
"We hit the limit of max connections or we could not remove the old one, so retrying"
)
hass.config_entries.async_schedule_reload(entry.entry_id) hass.config_entries.async_schedule_reload(entry.entry_id)
client.max_connections_reached_callback = _handle_max_connections client.max_connections_reached_callback = _handle_max_connections
@ -147,7 +152,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: SmartThingsConfigEntry)
if (old_identifier := entry.data.get(CONF_SUBSCRIPTION_ID)) is not None: if (old_identifier := entry.data.get(CONF_SUBSCRIPTION_ID)) is not None:
_LOGGER.debug("Trying to delete old subscription %s", old_identifier) _LOGGER.debug("Trying to delete old subscription %s", old_identifier)
try:
await client.delete_subscription(old_identifier) await client.delete_subscription(old_identifier)
except SmartThingsConnectionError as err:
raise ConfigEntryNotReady("Could not delete old subscription") from err
_LOGGER.debug("Trying to create a new subscription") _LOGGER.debug("Trying to create a new subscription")
try: try:
@ -274,6 +282,7 @@ async def async_unload_entry(
"""Unload a config entry.""" """Unload a config entry."""
client = entry.runtime_data.client client = entry.runtime_data.client
if (subscription_id := entry.data.get(CONF_SUBSCRIPTION_ID)) is not None: if (subscription_id := entry.data.get(CONF_SUBSCRIPTION_ID)) is not None:
with contextlib.suppress(SmartThingsConnectionError):
await client.delete_subscription(subscription_id) await client.delete_subscription(subscription_id)
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
@ -355,9 +364,7 @@ KEEP_CAPABILITY_QUIRK: dict[
} }
def process_status( def process_status(status: dict[str, ComponentStatus]) -> dict[str, ComponentStatus]:
status: dict[str, dict[Capability | str, dict[Attribute | str, 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: if (main_component := status.get(MAIN)) is None:
return status return status

View File

@ -174,9 +174,7 @@ def get_main_component_category(
device: FullDevice, device: FullDevice,
) -> Category | str: ) -> Category | str:
"""Get the main component of a device.""" """Get the main component of a device."""
main = next( main = device.device.components[MAIN]
component for component in device.device.components if component.id == MAIN
)
return main.user_category or main.manufacturer_category return main.user_category or main.manufacturer_category

View File

@ -8,9 +8,9 @@ from pysmartthings import (
Attribute, Attribute,
Capability, Capability,
Command, Command,
ComponentStatus,
DeviceEvent, DeviceEvent,
SmartThings, SmartThings,
Status,
) )
from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.device_registry import DeviceInfo
@ -38,7 +38,7 @@ class SmartThingsEntity(Entity):
self.client = client self.client = client
self.capabilities = capabilities self.capabilities = capabilities
self.component = component self.component = component
self._internal_state: dict[Capability | str, dict[Attribute | str, Status]] = { self._internal_state: ComponentStatus = {
capability: device.status[component][capability] capability: device.status[component][capability]
for capability in capabilities for capability in capabilities
if capability in device.status[component] if capability in device.status[component]

View File

@ -22,10 +22,12 @@ async def async_setup_entry(
"""Add events for a config entry.""" """Add events for a config entry."""
entry_data = entry.runtime_data entry_data = entry.runtime_data
async_add_entities( async_add_entities(
SmartThingsButtonEvent(entry_data.client, device, component) SmartThingsButtonEvent(
entry_data.client, device, device.device.components[component]
)
for device in entry_data.devices.values() for device in entry_data.devices.values()
for component in device.device.components for component, capabilities in device.status.items()
if Capability.BUTTON in component.capabilities if Capability.BUTTON in capabilities
) )

View File

@ -30,5 +30,5 @@
"iot_class": "cloud_push", "iot_class": "cloud_push",
"loggers": ["pysmartthings"], "loggers": ["pysmartthings"],
"quality_scale": "bronze", "quality_scale": "bronze",
"requirements": ["pysmartthings==2.7.4"] "requirements": ["pysmartthings==3.0.0"]
} }

View File

@ -47,8 +47,8 @@ class SmartThingsValve(SmartThingsEntity, ValveEntity):
"""Init the class.""" """Init the class."""
super().__init__(client, device, {Capability.VALVE}) super().__init__(client, device, {Capability.VALVE})
self._attr_device_class = DEVICE_CLASS_MAP.get( self._attr_device_class = DEVICE_CLASS_MAP.get(
device.device.components[0].user_category device.device.components[MAIN].user_category
or device.device.components[0].manufacturer_category or device.device.components[MAIN].manufacturer_category
) )
async def async_open_valve(self) -> None: async def async_open_valve(self) -> None:

2
requirements_all.txt generated
View File

@ -2313,7 +2313,7 @@ pysma==0.7.5
pysmappee==0.2.29 pysmappee==0.2.29
# homeassistant.components.smartthings # homeassistant.components.smartthings
pysmartthings==2.7.4 pysmartthings==3.0.0
# homeassistant.components.smarty # homeassistant.components.smarty
pysmarty2==0.10.2 pysmarty2==0.10.2

View File

@ -1883,7 +1883,7 @@ pysma==0.7.5
pysmappee==0.2.29 pysmappee==0.2.29
# homeassistant.components.smartthings # homeassistant.components.smartthings
pysmartthings==2.7.4 pysmartthings==3.0.0
# homeassistant.components.smarty # homeassistant.components.smarty
pysmarty2==0.10.2 pysmarty2==0.10.2

View File

@ -3,7 +3,7 @@
from typing import Any from typing import Any
from unittest.mock import AsyncMock from unittest.mock import AsyncMock
from pysmartthings.models import Attribute, Capability, DeviceEvent from pysmartthings import Attribute, Capability, DeviceEvent
from syrupy import SnapshotAssertion from syrupy import SnapshotAssertion
from homeassistant.components.smartthings.const import MAIN from homeassistant.components.smartthings.const import MAIN

View File

@ -4,7 +4,7 @@ from collections.abc import Generator
import time import time
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from pysmartthings.models import ( from pysmartthings import (
DeviceResponse, DeviceResponse,
DeviceStatus, DeviceStatus,
LocationResponse, LocationResponse,

View File

@ -8,9 +8,10 @@ from pysmartthings import (
Capability, Capability,
DeviceResponse, DeviceResponse,
DeviceStatus, DeviceStatus,
Lifecycle,
SmartThingsSinkError, SmartThingsSinkError,
Subscription,
) )
from pysmartthings.models import Lifecycle, Subscription
import pytest import pytest
from syrupy import SnapshotAssertion from syrupy import SnapshotAssertion