mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Update demetriek to v1.0.0 (#132765)
This commit is contained in:
parent
1929b368fe
commit
1256a7ea96
@ -26,5 +26,5 @@ async def async_get_config_entry_diagnostics(
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: LaMetricDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
# Round-trip via JSON to trigger serialization
|
||||
data = json.loads(coordinator.data.json())
|
||||
data = json.loads(coordinator.data.to_json())
|
||||
return async_redact_data(data, TO_REDACT)
|
||||
|
@ -13,7 +13,7 @@
|
||||
"integration_type": "device",
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["demetriek"],
|
||||
"requirements": ["demetriek==0.4.0"],
|
||||
"requirements": ["demetriek==1.0.0"],
|
||||
"ssdp": [
|
||||
{
|
||||
"deviceType": "urn:schemas-upnp-org:device:LaMetric:1"
|
||||
|
@ -5,12 +5,14 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
|
||||
from demetriek import (
|
||||
AlarmSound,
|
||||
LaMetricDevice,
|
||||
LaMetricError,
|
||||
Model,
|
||||
Notification,
|
||||
NotificationIconType,
|
||||
NotificationPriority,
|
||||
NotificationSound,
|
||||
Simple,
|
||||
Sound,
|
||||
)
|
||||
@ -18,8 +20,9 @@ from demetriek import (
|
||||
from homeassistant.components.notify import ATTR_DATA, BaseNotificationService
|
||||
from homeassistant.const import CONF_ICON
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.enum import try_parse_enum
|
||||
|
||||
from .const import CONF_CYCLES, CONF_ICON_TYPE, CONF_PRIORITY, CONF_SOUND, DOMAIN
|
||||
from .coordinator import LaMetricDataUpdateCoordinator
|
||||
@ -53,7 +56,12 @@ class LaMetricNotificationService(BaseNotificationService):
|
||||
|
||||
sound = None
|
||||
if CONF_SOUND in data:
|
||||
sound = Sound(sound=data[CONF_SOUND], category=None)
|
||||
snd: AlarmSound | NotificationSound | None
|
||||
if (snd := try_parse_enum(AlarmSound, data[CONF_SOUND])) is None and (
|
||||
snd := try_parse_enum(NotificationSound, data[CONF_SOUND])
|
||||
) is None:
|
||||
raise ServiceValidationError("Unknown sound provided")
|
||||
sound = Sound(sound=snd, category=None)
|
||||
|
||||
notification = Notification(
|
||||
icon_type=NotificationIconType(data.get(CONF_ICON_TYPE, "none")),
|
||||
|
@ -19,8 +19,9 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_DEVICE_ID, CONF_ICON
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.util.enum import try_parse_enum
|
||||
|
||||
from .const import (
|
||||
CONF_CYCLES,
|
||||
@ -118,7 +119,12 @@ async def async_send_notification(
|
||||
"""Send a notification to an LaMetric device."""
|
||||
sound = None
|
||||
if CONF_SOUND in call.data:
|
||||
sound = Sound(sound=call.data[CONF_SOUND], category=None)
|
||||
snd: AlarmSound | NotificationSound | None
|
||||
if (snd := try_parse_enum(AlarmSound, call.data[CONF_SOUND])) is None and (
|
||||
snd := try_parse_enum(NotificationSound, call.data[CONF_SOUND])
|
||||
) is None:
|
||||
raise ServiceValidationError("Unknown sound provided")
|
||||
sound = Sound(sound=snd, category=None)
|
||||
|
||||
notification = Notification(
|
||||
icon_type=NotificationIconType(call.data[CONF_ICON_TYPE]),
|
||||
|
@ -746,7 +746,7 @@ defusedxml==0.7.1
|
||||
deluge-client==1.10.2
|
||||
|
||||
# homeassistant.components.lametric
|
||||
demetriek==0.4.0
|
||||
demetriek==1.0.0
|
||||
|
||||
# homeassistant.components.denonavr
|
||||
denonavr==1.0.1
|
||||
|
@ -636,7 +636,7 @@ defusedxml==0.7.1
|
||||
deluge-client==1.10.2
|
||||
|
||||
# homeassistant.components.lametric
|
||||
demetriek==0.4.0
|
||||
demetriek==1.0.0
|
||||
|
||||
# homeassistant.components.denonavr
|
||||
denonavr==1.0.1
|
||||
|
@ -6,7 +6,6 @@ from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from demetriek import CloudDevice, Device
|
||||
from pydantic import parse_raw_as # pylint: disable=no-name-in-module
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.application_credentials import (
|
||||
@ -18,7 +17,7 @@ from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_MAC
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
from tests.common import MockConfigEntry, load_fixture, load_json_array_fixture
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@ -61,9 +60,10 @@ def mock_lametric_cloud() -> Generator[MagicMock]:
|
||||
"homeassistant.components.lametric.config_flow.LaMetricCloud", autospec=True
|
||||
) as lametric_mock:
|
||||
lametric = lametric_mock.return_value
|
||||
lametric.devices.return_value = parse_raw_as(
|
||||
list[CloudDevice], load_fixture("cloud_devices.json", DOMAIN)
|
||||
)
|
||||
lametric.devices.return_value = [
|
||||
CloudDevice.from_dict(cloud_device)
|
||||
for cloud_device in load_json_array_fixture("cloud_devices.json", DOMAIN)
|
||||
]
|
||||
yield lametric
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ def mock_lametric(device_fixture: str) -> Generator[MagicMock]:
|
||||
lametric = lametric_mock.return_value
|
||||
lametric.api_key = "mock-api-key"
|
||||
lametric.host = "127.0.0.1"
|
||||
lametric.device.return_value = Device.parse_raw(
|
||||
lametric.device.return_value = Device.from_json(
|
||||
load_fixture(f"{device_fixture}.json", DOMAIN)
|
||||
)
|
||||
yield lametric
|
||||
|
@ -26,6 +26,9 @@
|
||||
'brightness_mode': 'auto',
|
||||
'display_type': 'mixed',
|
||||
'height': 8,
|
||||
'screensaver': dict({
|
||||
'enabled': False,
|
||||
}),
|
||||
'width': 37,
|
||||
}),
|
||||
'mode': 'auto',
|
||||
|
@ -100,7 +100,7 @@ async def test_notification_options(
|
||||
assert len(notification.model.frames) == 1
|
||||
frame = notification.model.frames[0]
|
||||
assert type(frame) is Simple
|
||||
assert frame.icon == 1234
|
||||
assert frame.icon == "1234"
|
||||
assert frame.text == "The secret of getting ahead is getting started"
|
||||
|
||||
|
||||
|
@ -190,7 +190,7 @@ async def test_service_message(
|
||||
assert len(notification.model.frames) == 1
|
||||
frame = notification.model.frames[0]
|
||||
assert type(frame) is Simple
|
||||
assert frame.icon == 6916
|
||||
assert frame.icon == "6916"
|
||||
assert frame.text == "Meow!"
|
||||
|
||||
mock_lametric.notify.side_effect = LaMetricError
|
||||
|
Loading…
x
Reference in New Issue
Block a user