mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Bump pysmartthings to 3.0.0 (#141058)
* Bump pysmartthings to 2.7.5 * Bump to pysmartthings 3.0.0
This commit is contained in:
parent
ee3b31c01f
commit
11877a3b12
@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
import contextlib
|
||||
from dataclasses import dataclass
|
||||
from http import HTTPStatus
|
||||
import logging
|
||||
@ -12,15 +13,17 @@ from aiohttp import ClientResponseError
|
||||
from pysmartthings import (
|
||||
Attribute,
|
||||
Capability,
|
||||
ComponentStatus,
|
||||
Device,
|
||||
DeviceEvent,
|
||||
Lifecycle,
|
||||
Scene,
|
||||
SmartThings,
|
||||
SmartThingsAuthenticationFailedError,
|
||||
SmartThingsConnectionError,
|
||||
SmartThingsSinkError,
|
||||
Status,
|
||||
)
|
||||
from pysmartthings.models import Lifecycle
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
@ -72,7 +75,7 @@ class FullDevice:
|
||||
"""Define an object to hold device data."""
|
||||
|
||||
device: Device
|
||||
status: dict[str, dict[Capability | str, dict[Attribute | str, Status]]]
|
||||
status: dict[str, ComponentStatus]
|
||||
|
||||
|
||||
type SmartThingsConfigEntry = ConfigEntry[SmartThingsData]
|
||||
@ -124,7 +127,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: SmartThingsConfigEntry)
|
||||
client.refresh_token_function = _refresh_token
|
||||
|
||||
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)
|
||||
|
||||
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:
|
||||
_LOGGER.debug("Trying to delete old subscription %s", old_identifier)
|
||||
await client.delete_subscription(old_identifier)
|
||||
try:
|
||||
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")
|
||||
try:
|
||||
@ -274,7 +282,8 @@ async def async_unload_entry(
|
||||
"""Unload a config entry."""
|
||||
client = entry.runtime_data.client
|
||||
if (subscription_id := entry.data.get(CONF_SUBSCRIPTION_ID)) is not None:
|
||||
await client.delete_subscription(subscription_id)
|
||||
with contextlib.suppress(SmartThingsConnectionError):
|
||||
await client.delete_subscription(subscription_id)
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
@ -355,9 +364,7 @@ KEEP_CAPABILITY_QUIRK: dict[
|
||||
}
|
||||
|
||||
|
||||
def process_status(
|
||||
status: dict[str, dict[Capability | str, dict[Attribute | str, Status]]],
|
||||
) -> dict[str, dict[Capability | str, dict[Attribute | str, Status]]]:
|
||||
def process_status(status: dict[str, ComponentStatus]) -> dict[str, ComponentStatus]:
|
||||
"""Remove disabled capabilities from status."""
|
||||
if (main_component := status.get(MAIN)) is None:
|
||||
return status
|
||||
|
@ -174,9 +174,7 @@ def get_main_component_category(
|
||||
device: FullDevice,
|
||||
) -> Category | str:
|
||||
"""Get the main component of a device."""
|
||||
main = next(
|
||||
component for component in device.device.components if component.id == MAIN
|
||||
)
|
||||
main = device.device.components[MAIN]
|
||||
return main.user_category or main.manufacturer_category
|
||||
|
||||
|
||||
|
@ -8,9 +8,9 @@ from pysmartthings import (
|
||||
Attribute,
|
||||
Capability,
|
||||
Command,
|
||||
ComponentStatus,
|
||||
DeviceEvent,
|
||||
SmartThings,
|
||||
Status,
|
||||
)
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
@ -38,7 +38,7 @@ class SmartThingsEntity(Entity):
|
||||
self.client = client
|
||||
self.capabilities = capabilities
|
||||
self.component = component
|
||||
self._internal_state: dict[Capability | str, dict[Attribute | str, Status]] = {
|
||||
self._internal_state: ComponentStatus = {
|
||||
capability: device.status[component][capability]
|
||||
for capability in capabilities
|
||||
if capability in device.status[component]
|
||||
|
@ -22,10 +22,12 @@ async def async_setup_entry(
|
||||
"""Add events for a config entry."""
|
||||
entry_data = entry.runtime_data
|
||||
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 component in device.device.components
|
||||
if Capability.BUTTON in component.capabilities
|
||||
for component, capabilities in device.status.items()
|
||||
if Capability.BUTTON in capabilities
|
||||
)
|
||||
|
||||
|
||||
|
@ -30,5 +30,5 @@
|
||||
"iot_class": "cloud_push",
|
||||
"loggers": ["pysmartthings"],
|
||||
"quality_scale": "bronze",
|
||||
"requirements": ["pysmartthings==2.7.4"]
|
||||
"requirements": ["pysmartthings==3.0.0"]
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ class SmartThingsValve(SmartThingsEntity, ValveEntity):
|
||||
"""Init the class."""
|
||||
super().__init__(client, device, {Capability.VALVE})
|
||||
self._attr_device_class = DEVICE_CLASS_MAP.get(
|
||||
device.device.components[0].user_category
|
||||
or device.device.components[0].manufacturer_category
|
||||
device.device.components[MAIN].user_category
|
||||
or device.device.components[MAIN].manufacturer_category
|
||||
)
|
||||
|
||||
async def async_open_valve(self) -> None:
|
||||
|
2
requirements_all.txt
generated
2
requirements_all.txt
generated
@ -2313,7 +2313,7 @@ pysma==0.7.5
|
||||
pysmappee==0.2.29
|
||||
|
||||
# homeassistant.components.smartthings
|
||||
pysmartthings==2.7.4
|
||||
pysmartthings==3.0.0
|
||||
|
||||
# homeassistant.components.smarty
|
||||
pysmarty2==0.10.2
|
||||
|
2
requirements_test_all.txt
generated
2
requirements_test_all.txt
generated
@ -1883,7 +1883,7 @@ pysma==0.7.5
|
||||
pysmappee==0.2.29
|
||||
|
||||
# homeassistant.components.smartthings
|
||||
pysmartthings==2.7.4
|
||||
pysmartthings==3.0.0
|
||||
|
||||
# homeassistant.components.smarty
|
||||
pysmarty2==0.10.2
|
||||
|
@ -3,7 +3,7 @@
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from pysmartthings.models import Attribute, Capability, DeviceEvent
|
||||
from pysmartthings import Attribute, Capability, DeviceEvent
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.smartthings.const import MAIN
|
||||
|
@ -4,7 +4,7 @@ from collections.abc import Generator
|
||||
import time
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from pysmartthings.models import (
|
||||
from pysmartthings import (
|
||||
DeviceResponse,
|
||||
DeviceStatus,
|
||||
LocationResponse,
|
||||
|
@ -8,9 +8,10 @@ from pysmartthings import (
|
||||
Capability,
|
||||
DeviceResponse,
|
||||
DeviceStatus,
|
||||
Lifecycle,
|
||||
SmartThingsSinkError,
|
||||
Subscription,
|
||||
)
|
||||
from pysmartthings.models import Lifecycle, Subscription
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user