Implement Identify button and Cloud connection toggle for HomeWizard Watermeter (#113814)
This commit is contained in:
parent
5c69e0d2c6
commit
788813aad6
10 changed files with 94 additions and 19 deletions
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||
import logging
|
||||
|
||||
from homewizard_energy import HomeWizardEnergy
|
||||
from homewizard_energy.const import SUPPORTS_IDENTIFY, SUPPORTS_STATE, SUPPORTS_SYSTEM
|
||||
from homewizard_energy.const import SUPPORTS_IDENTIFY, SUPPORTS_STATE
|
||||
from homewizard_energy.errors import DisabledError, RequestError, UnsupportedError
|
||||
from homewizard_energy.models import Device
|
||||
|
||||
|
@ -53,8 +53,7 @@ class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry]
|
|||
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 UnsupportedError as ex:
|
||||
# Old firmware, ignore
|
||||
|
@ -94,13 +93,6 @@ class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry]
|
|||
|
||||
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:
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
"iot_class": "local_polling",
|
||||
"loggers": ["homewizard_energy"],
|
||||
"quality_scale": "platinum",
|
||||
"requirements": ["python-homewizard-energy==4.3.1"],
|
||||
"requirements": ["python-homewizard-energy==v5.0.0"],
|
||||
"zeroconf": ["_hwenergy._tcp.local."]
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ SWITCHES = [
|
|||
key="cloud_connection",
|
||||
translation_key="cloud_connection",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
create_fn=lambda coordinator: coordinator.supports_system(),
|
||||
create_fn=lambda _: True,
|
||||
available_fn=lambda data: data.system is not 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),
|
||||
|
|
|
@ -2229,7 +2229,7 @@ python-gitlab==1.6.0
|
|||
python-homeassistant-analytics==0.6.0
|
||||
|
||||
# homeassistant.components.homewizard
|
||||
python-homewizard-energy==4.3.1
|
||||
python-homewizard-energy==v5.0.0
|
||||
|
||||
# homeassistant.components.hp_ilo
|
||||
python-hpilo==4.4.3
|
||||
|
|
|
@ -1720,7 +1720,7 @@ python-fullykiosk==0.0.12
|
|||
python-homeassistant-analytics==0.6.0
|
||||
|
||||
# homeassistant.components.homewizard
|
||||
python-homewizard-energy==4.3.1
|
||||
python-homewizard-energy==v5.0.0
|
||||
|
||||
# homeassistant.components.izone
|
||||
python-izone==1.2.9
|
||||
|
|
3
tests/components/homewizard/fixtures/HWE-WTR/system.json
Normal file
3
tests/components/homewizard/fixtures/HWE-WTR/system.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"cloud_enabled": true
|
||||
}
|
|
@ -544,7 +544,9 @@
|
|||
'serial': '**REDACTED**',
|
||||
}),
|
||||
'state': None,
|
||||
'system': None,
|
||||
'system': dict({
|
||||
'cloud_enabled': True,
|
||||
}),
|
||||
}),
|
||||
'entry': dict({
|
||||
'ip_address': '**REDACTED**',
|
||||
|
|
|
@ -641,6 +641,86 @@
|
|||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_entities[HWE-WTR-switch.device_cloud_connection-system_set-cloud_enabled]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Device Cloud connection',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.device_cloud_connection',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_entities[HWE-WTR-switch.device_cloud_connection-system_set-cloud_enabled].1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'switch',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.device_cloud_connection',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Cloud connection',
|
||||
'platform': 'homewizard',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'cloud_connection',
|
||||
'unique_id': 'aabbccddeeff_cloud_connection',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_entities[HWE-WTR-switch.device_cloud_connection-system_set-cloud_enabled].2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
tuple(
|
||||
'mac',
|
||||
'3c:39:e7:aa:bb:cc',
|
||||
),
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'homewizard',
|
||||
'3c39e7aabbcc',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'HomeWizard',
|
||||
'model': 'HWE-WTR',
|
||||
'name': 'Device',
|
||||
'name_by_user': None,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '2.03',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_entities[SDM230-switch.device_cloud_connection-system_set-cloud_enabled]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
|
|
|
@ -18,9 +18,7 @@ pytestmark = [
|
|||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"device_fixture", ["HWE-WTR", "SDM230", "SDM630", "HWE-KWH1", "HWE-KWH3"]
|
||||
)
|
||||
@pytest.mark.parametrize("device_fixture", ["SDM230", "SDM630", "HWE-KWH1", "HWE-KWH3"])
|
||||
async def test_identify_button_entity_not_loaded_when_not_available(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
|
|
|
@ -42,7 +42,6 @@ pytestmark = [
|
|||
[
|
||||
"switch.device",
|
||||
"switch.device_switch_lock",
|
||||
"switch.device_cloud_connection",
|
||||
],
|
||||
),
|
||||
(
|
||||
|
@ -93,6 +92,7 @@ async def test_entities_not_created_for_device(
|
|||
("HWE-SKT-21", "switch.device", "state_set", "power_on"),
|
||||
("HWE-SKT-21", "switch.device_switch_lock", "state_set", "switch_lock"),
|
||||
("HWE-SKT-21", "switch.device_cloud_connection", "system_set", "cloud_enabled"),
|
||||
("HWE-WTR", "switch.device_cloud_connection", "system_set", "cloud_enabled"),
|
||||
("SDM230", "switch.device_cloud_connection", "system_set", "cloud_enabled"),
|
||||
("SDM630", "switch.device_cloud_connection", "system_set", "cloud_enabled"),
|
||||
("HWE-KWH1", "switch.device_cloud_connection", "system_set", "cloud_enabled"),
|
||||
|
|
Loading…
Add table
Reference in a new issue