mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Bump python-homewizard-energy to 2.0.1 (#91097)
This commit is contained in:
parent
bbf2d0e6ad
commit
7a8159052e
@ -1,4 +1,5 @@
|
|||||||
"""Support for HomeWizard buttons."""
|
"""Support for HomeWizard buttons."""
|
||||||
|
|
||||||
from homeassistant.components.button import ButtonEntity
|
from homeassistant.components.button import ButtonEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
@ -16,7 +17,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Identify button."""
|
"""Set up the Identify button."""
|
||||||
coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
if coordinator.data.features.has_identify:
|
if coordinator.supports_identify():
|
||||||
async_add_entities([HomeWizardIdentifyButton(coordinator, entry)])
|
async_add_entities([HomeWizardIdentifyButton(coordinator, entry)])
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homewizard_energy.features import Features
|
|
||||||
from homewizard_energy.models import Data, Device, State, System
|
from homewizard_energy.models import Data, Device, State, System
|
||||||
|
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
@ -30,6 +29,5 @@ class DeviceResponseEntry:
|
|||||||
|
|
||||||
device: Device
|
device: Device
|
||||||
data: Data
|
data: Data
|
||||||
features: Features
|
state: State | None = None
|
||||||
state: State | None
|
|
||||||
system: System | None = None
|
system: System | None = None
|
||||||
|
@ -4,7 +4,9 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homewizard_energy import HomeWizardEnergy
|
from homewizard_energy import HomeWizardEnergy
|
||||||
|
from homewizard_energy.const import SUPPORTS_IDENTIFY, SUPPORTS_STATE, SUPPORTS_SYSTEM
|
||||||
from homewizard_energy.errors import DisabledError, RequestError
|
from homewizard_energy.errors import DisabledError, RequestError
|
||||||
|
from homewizard_energy.models import Device
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -39,11 +41,12 @@ class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry]
|
|||||||
data = DeviceResponseEntry(
|
data = DeviceResponseEntry(
|
||||||
device=await self.api.device(),
|
device=await self.api.device(),
|
||||||
data=await self.api.data(),
|
data=await self.api.data(),
|
||||||
features=await self.api.features(),
|
|
||||||
state=await self.api.state(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if data.features.has_system:
|
if self.supports_state(data.device):
|
||||||
|
data.state = await self.api.state()
|
||||||
|
|
||||||
|
if self.supports_system(data.device):
|
||||||
data.system = await self.api.system()
|
data.system = await self.api.system()
|
||||||
|
|
||||||
except RequestError as ex:
|
except RequestError as ex:
|
||||||
@ -61,4 +64,27 @@ class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry]
|
|||||||
|
|
||||||
self.api_disabled = False
|
self.api_disabled = False
|
||||||
|
|
||||||
|
self.data = data
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def supports_state(self, device: Device | None = None) -> bool:
|
||||||
|
"""Return True if the device supports state."""
|
||||||
|
|
||||||
|
if device is None:
|
||||||
|
device = self.data.device
|
||||||
|
|
||||||
|
return device.product_type in SUPPORTS_STATE
|
||||||
|
|
||||||
|
def supports_system(self, device: Device | None = None) -> bool:
|
||||||
|
"""Return True if the device supports system."""
|
||||||
|
if device is None:
|
||||||
|
device = self.data.device
|
||||||
|
|
||||||
|
return device.product_type in SUPPORTS_SYSTEM
|
||||||
|
|
||||||
|
def supports_identify(self, device: Device | None = None) -> bool:
|
||||||
|
"""Return True if the device supports identify."""
|
||||||
|
if device is None:
|
||||||
|
device = self.data.device
|
||||||
|
|
||||||
|
return device.product_type in SUPPORTS_IDENTIFY
|
||||||
|
@ -8,6 +8,6 @@
|
|||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"loggers": ["homewizard_energy"],
|
"loggers": ["homewizard_energy"],
|
||||||
"quality_scale": "platinum",
|
"quality_scale": "platinum",
|
||||||
"requirements": ["python-homewizard-energy==1.8.0"],
|
"requirements": ["python-homewizard-energy==2.0.1"],
|
||||||
"zeroconf": ["_hwenergy._tcp.local."]
|
"zeroconf": ["_hwenergy._tcp.local."]
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up numbers for device."""
|
"""Set up numbers for device."""
|
||||||
coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
if coordinator.data.state:
|
if coordinator.supports_state():
|
||||||
async_add_entities([HWEnergyNumberEntity(coordinator, entry)])
|
async_add_entities([HWEnergyNumberEntity(coordinator, entry)])
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ from .helpers import homewizard_exception_handler
|
|||||||
class HomeWizardEntityDescriptionMixin:
|
class HomeWizardEntityDescriptionMixin:
|
||||||
"""Mixin values for HomeWizard entities."""
|
"""Mixin values for HomeWizard entities."""
|
||||||
|
|
||||||
create_fn: Callable[[DeviceResponseEntry], bool]
|
create_fn: Callable[[HWEnergyDeviceUpdateCoordinator], bool]
|
||||||
available_fn: Callable[[DeviceResponseEntry], bool]
|
available_fn: Callable[[DeviceResponseEntry], bool]
|
||||||
is_on_fn: Callable[[DeviceResponseEntry], bool | None]
|
is_on_fn: Callable[[DeviceResponseEntry], bool | None]
|
||||||
set_fn: Callable[[HomeWizardEnergy, bool], Awaitable[Any]]
|
set_fn: Callable[[HomeWizardEnergy, bool], Awaitable[Any]]
|
||||||
@ -46,7 +46,7 @@ SWITCHES = [
|
|||||||
HomeWizardSwitchEntityDescription(
|
HomeWizardSwitchEntityDescription(
|
||||||
key="power_on",
|
key="power_on",
|
||||||
device_class=SwitchDeviceClass.OUTLET,
|
device_class=SwitchDeviceClass.OUTLET,
|
||||||
create_fn=lambda data: data.state is not None,
|
create_fn=lambda coordinator: coordinator.supports_state(),
|
||||||
available_fn=lambda data: data.state is not None and not data.state.switch_lock,
|
available_fn=lambda data: data.state is not None and not data.state.switch_lock,
|
||||||
is_on_fn=lambda data: data.state.power_on if data.state else None,
|
is_on_fn=lambda data: data.state.power_on if data.state else None,
|
||||||
set_fn=lambda api, active: api.state_set(power_on=active),
|
set_fn=lambda api, active: api.state_set(power_on=active),
|
||||||
@ -57,7 +57,7 @@ SWITCHES = [
|
|||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
icon="mdi:lock",
|
icon="mdi:lock",
|
||||||
icon_off="mdi:lock-open",
|
icon_off="mdi:lock-open",
|
||||||
create_fn=lambda data: data.state is not None,
|
create_fn=lambda coordinator: coordinator.supports_state(),
|
||||||
available_fn=lambda data: data.state is not None,
|
available_fn=lambda data: data.state is not None,
|
||||||
is_on_fn=lambda data: data.state.switch_lock if data.state else None,
|
is_on_fn=lambda data: data.state.switch_lock if data.state else None,
|
||||||
set_fn=lambda api, active: api.state_set(switch_lock=active),
|
set_fn=lambda api, active: api.state_set(switch_lock=active),
|
||||||
@ -68,7 +68,7 @@ SWITCHES = [
|
|||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
icon="mdi:cloud",
|
icon="mdi:cloud",
|
||||||
icon_off="mdi:cloud-off-outline",
|
icon_off="mdi:cloud-off-outline",
|
||||||
create_fn=lambda data: data.system is not None,
|
create_fn=lambda coordinator: coordinator.supports_system(),
|
||||||
available_fn=lambda data: data.system is not None,
|
available_fn=lambda data: data.system is not None,
|
||||||
is_on_fn=lambda data: data.system.cloud_enabled if data.system else None,
|
is_on_fn=lambda data: data.system.cloud_enabled if data.system else None,
|
||||||
set_fn=lambda api, active: api.system_set(cloud_enabled=active),
|
set_fn=lambda api, active: api.system_set(cloud_enabled=active),
|
||||||
@ -91,7 +91,7 @@ async def async_setup_entry(
|
|||||||
entry=entry,
|
entry=entry,
|
||||||
)
|
)
|
||||||
for description in SWITCHES
|
for description in SWITCHES
|
||||||
if description.available_fn(coordinator.data)
|
if description.create_fn(coordinator)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2054,7 +2054,7 @@ python-gc100==1.0.3a0
|
|||||||
python-gitlab==1.6.0
|
python-gitlab==1.6.0
|
||||||
|
|
||||||
# homeassistant.components.homewizard
|
# homeassistant.components.homewizard
|
||||||
python-homewizard-energy==1.8.0
|
python-homewizard-energy==2.0.1
|
||||||
|
|
||||||
# homeassistant.components.hp_ilo
|
# homeassistant.components.hp_ilo
|
||||||
python-hpilo==4.3
|
python-hpilo==4.3
|
||||||
|
@ -1477,7 +1477,7 @@ python-ecobee-api==0.2.14
|
|||||||
python-fullykiosk==0.0.12
|
python-fullykiosk==0.0.12
|
||||||
|
|
||||||
# homeassistant.components.homewizard
|
# homeassistant.components.homewizard
|
||||||
python-homewizard-energy==1.8.0
|
python-homewizard-energy==2.0.1
|
||||||
|
|
||||||
# homeassistant.components.izone
|
# homeassistant.components.izone
|
||||||
python-izone==1.2.9
|
python-izone==1.2.9
|
||||||
|
@ -3,7 +3,6 @@ from collections.abc import Generator
|
|||||||
import json
|
import json
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
from homewizard_energy.features import Features
|
|
||||||
from homewizard_energy.models import Data, Device, State, System
|
from homewizard_energy.models import Data, Device, State, System
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -44,7 +43,6 @@ def mock_homewizardenergy():
|
|||||||
"homeassistant.components.homewizard.coordinator.HomeWizardEnergy",
|
"homeassistant.components.homewizard.coordinator.HomeWizardEnergy",
|
||||||
) as device:
|
) as device:
|
||||||
client = device.return_value
|
client = device.return_value
|
||||||
client.features = AsyncMock(return_value=Features("HWE-SKT", "3.01"))
|
|
||||||
client.device = AsyncMock(
|
client.device = AsyncMock(
|
||||||
side_effect=lambda: Device.from_dict(
|
side_effect=lambda: Device.from_dict(
|
||||||
json.loads(load_fixture("homewizard/device.json"))
|
json.loads(load_fixture("homewizard/device.json"))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"product_type": "HWE-P1",
|
"product_type": "HWE-SKT",
|
||||||
"product_name": "P1 Meter",
|
"product_name": "P1 Meter",
|
||||||
"serial": "3c39e7aabbcc",
|
"serial": "3c39e7aabbcc",
|
||||||
"firmware_version": "2.11",
|
"firmware_version": "2.11",
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
from unittest.mock import AsyncMock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from homewizard_energy.features import Features
|
|
||||||
from homewizard_energy.models import Data, Device
|
from homewizard_energy.models import Data, Device
|
||||||
|
|
||||||
|
|
||||||
@ -29,9 +28,6 @@ def get_mock_device(
|
|||||||
mock_device.data = AsyncMock(return_value=Data.from_dict({}))
|
mock_device.data = AsyncMock(return_value=Data.from_dict({}))
|
||||||
mock_device.state = AsyncMock(return_value=None)
|
mock_device.state = AsyncMock(return_value=None)
|
||||||
mock_device.system = AsyncMock(return_value=None)
|
mock_device.system = AsyncMock(return_value=None)
|
||||||
mock_device.features = AsyncMock(
|
|
||||||
return_value=Features(product_type, firmware_version)
|
|
||||||
)
|
|
||||||
|
|
||||||
mock_device.close = AsyncMock()
|
mock_device.close = AsyncMock()
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ async def test_identify_button_entity_not_loaded_when_not_available(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Does not load button when device has no support for it."""
|
"""Does not load button when device has no support for it."""
|
||||||
|
|
||||||
api = get_mock_device(product_type="HWE-P1")
|
api = get_mock_device(product_type="SDM230-WIFI")
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.homewizard.coordinator.HomeWizardEnergy",
|
"homeassistant.components.homewizard.coordinator.HomeWizardEnergy",
|
||||||
|
@ -21,7 +21,7 @@ async def test_diagnostics(
|
|||||||
"data": {
|
"data": {
|
||||||
"device": {
|
"device": {
|
||||||
"product_name": "P1 Meter",
|
"product_name": "P1 Meter",
|
||||||
"product_type": "HWE-P1",
|
"product_type": "HWE-SKT",
|
||||||
"serial": REDACTED,
|
"serial": REDACTED,
|
||||||
"api_version": "v1",
|
"api_version": "v1",
|
||||||
"firmware_version": "2.11",
|
"firmware_version": "2.11",
|
||||||
|
@ -44,7 +44,7 @@ async def test_number_loads_entities(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity does load number when brightness is available."""
|
"""Test entity does load number when brightness is available."""
|
||||||
|
|
||||||
api = get_mock_device()
|
api = get_mock_device(product_type="HWE-SKT")
|
||||||
api.state = AsyncMock(return_value=State.from_dict({"brightness": 255}))
|
api.state = AsyncMock(return_value=State.from_dict({"brightness": 255}))
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
@ -81,7 +81,7 @@ async def test_brightness_level_set(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity turns sets light level."""
|
"""Test entity turns sets light level."""
|
||||||
|
|
||||||
api = get_mock_device()
|
api = get_mock_device(product_type="HWE-SKT")
|
||||||
api.state = AsyncMock(return_value=State.from_dict({"brightness": 255}))
|
api.state = AsyncMock(return_value=State.from_dict({"brightness": 255}))
|
||||||
|
|
||||||
def state_set(brightness):
|
def state_set(brightness):
|
||||||
@ -157,7 +157,7 @@ async def test_brightness_level_set_catches_requesterror(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity raises HomeAssistantError when RequestError was raised."""
|
"""Test entity raises HomeAssistantError when RequestError was raised."""
|
||||||
|
|
||||||
api = get_mock_device()
|
api = get_mock_device(product_type="HWE-SKT")
|
||||||
api.state = AsyncMock(return_value=State.from_dict({"brightness": 255}))
|
api.state = AsyncMock(return_value=State.from_dict({"brightness": 255}))
|
||||||
|
|
||||||
api.state_set = AsyncMock(side_effect=RequestError())
|
api.state_set = AsyncMock(side_effect=RequestError())
|
||||||
@ -193,7 +193,7 @@ async def test_brightness_level_set_catches_disablederror(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity raises HomeAssistantError when DisabledError was raised."""
|
"""Test entity raises HomeAssistantError when DisabledError was raised."""
|
||||||
|
|
||||||
api = get_mock_device()
|
api = get_mock_device(product_type="HWE-SKT")
|
||||||
api.state = AsyncMock(return_value=State.from_dict({"brightness": 255}))
|
api.state = AsyncMock(return_value=State.from_dict({"brightness": 255}))
|
||||||
|
|
||||||
api.state_set = AsyncMock(side_effect=DisabledError())
|
api.state_set = AsyncMock(side_effect=DisabledError())
|
||||||
@ -229,7 +229,7 @@ async def test_brightness_level_set_catches_invalid_value(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity raises ValueError when value was invalid."""
|
"""Test entity raises ValueError when value was invalid."""
|
||||||
|
|
||||||
api = get_mock_device()
|
api = get_mock_device(product_type="HWE-SKT")
|
||||||
api.state = AsyncMock(return_value=State.from_dict({"brightness": 255}))
|
api.state = AsyncMock(return_value=State.from_dict({"brightness": 255}))
|
||||||
|
|
||||||
def state_set(brightness):
|
def state_set(brightness):
|
||||||
|
@ -54,7 +54,7 @@ async def test_switch_loads_entities(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity loads smr version."""
|
"""Test entity loads smr version."""
|
||||||
|
|
||||||
api = get_mock_device()
|
api = get_mock_device(product_type="HWE-SKT")
|
||||||
api.state = AsyncMock(
|
api.state = AsyncMock(
|
||||||
return_value=State.from_dict({"power_on": False, "switch_lock": False})
|
return_value=State.from_dict({"power_on": False, "switch_lock": False})
|
||||||
)
|
)
|
||||||
@ -109,7 +109,7 @@ async def test_switch_power_on_off(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity turns switch on and off."""
|
"""Test entity turns switch on and off."""
|
||||||
|
|
||||||
api = get_mock_device()
|
api = get_mock_device(product_type="HWE-SKT")
|
||||||
api.state = AsyncMock(
|
api.state = AsyncMock(
|
||||||
return_value=State.from_dict({"power_on": False, "switch_lock": False})
|
return_value=State.from_dict({"power_on": False, "switch_lock": False})
|
||||||
)
|
)
|
||||||
@ -164,7 +164,7 @@ async def test_switch_lock_power_on_off(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity turns switch on and off."""
|
"""Test entity turns switch on and off."""
|
||||||
|
|
||||||
api = get_mock_device()
|
api = get_mock_device(product_type="HWE-SKT")
|
||||||
api.state = AsyncMock(
|
api.state = AsyncMock(
|
||||||
return_value=State.from_dict({"power_on": False, "switch_lock": False})
|
return_value=State.from_dict({"power_on": False, "switch_lock": False})
|
||||||
)
|
)
|
||||||
@ -228,7 +228,7 @@ async def test_switch_lock_sets_power_on_unavailable(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity turns switch on and off."""
|
"""Test entity turns switch on and off."""
|
||||||
|
|
||||||
api = get_mock_device()
|
api = get_mock_device(product_type="HWE-SKT")
|
||||||
api.state = AsyncMock(
|
api.state = AsyncMock(
|
||||||
return_value=State.from_dict({"power_on": True, "switch_lock": False})
|
return_value=State.from_dict({"power_on": True, "switch_lock": False})
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user