mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Fix HomeWizard code quality issues (#82973)
* Sort platforms a-z * Collect all switch entities and load in a single call * Add test for button press
This commit is contained in:
parent
663482fb10
commit
c2d372dd13
@ -10,7 +10,7 @@ from homewizard_energy.models import Data, Device, State, System
|
||||
from homeassistant.const import Platform
|
||||
|
||||
DOMAIN = "homewizard"
|
||||
PLATFORMS = [Platform.SENSOR, Platform.SWITCH, Platform.NUMBER, Platform.BUTTON]
|
||||
PLATFORMS = [Platform.BUTTON, Platform.NUMBER, Platform.SENSOR, Platform.SWITCH]
|
||||
|
||||
# Platform config.
|
||||
CONF_API_ENABLED = "api_enabled"
|
||||
|
@ -22,20 +22,16 @@ async def async_setup_entry(
|
||||
"""Set up switches."""
|
||||
coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
entities: list[SwitchEntity] = []
|
||||
|
||||
if coordinator.data["state"]:
|
||||
async_add_entities(
|
||||
[
|
||||
HWEnergyMainSwitchEntity(coordinator, entry),
|
||||
HWEnergySwitchLockEntity(coordinator, entry),
|
||||
]
|
||||
)
|
||||
entities.append(HWEnergyMainSwitchEntity(coordinator, entry))
|
||||
entities.append(HWEnergySwitchLockEntity(coordinator, entry))
|
||||
|
||||
if coordinator.data["system"]:
|
||||
async_add_entities(
|
||||
[
|
||||
HWEnergyEnableCloudEntity(hass, coordinator, entry),
|
||||
]
|
||||
)
|
||||
entities.append(HWEnergyEnableCloudEntity(hass, coordinator, entry))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class HWEnergySwitchEntity(
|
||||
|
@ -1,7 +1,8 @@
|
||||
"""Test the identify button for HomeWizard."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.const import ATTR_FRIENDLY_NAME
|
||||
from homeassistant.components import button
|
||||
from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_UNKNOWN
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .generator import get_mock_device
|
||||
@ -57,3 +58,34 @@ async def test_identify_button_is_loaded(
|
||||
entry = entity_registry.async_get("button.product_name_aabbccddeeff_identify")
|
||||
assert entry
|
||||
assert entry.unique_id == "aabbccddeeff_identify"
|
||||
|
||||
|
||||
async def test_cloud_connection_on_off(hass, mock_config_entry_data, mock_config_entry):
|
||||
"""Test the creation and values of the Litter-Robot button."""
|
||||
|
||||
api = get_mock_device(product_type="HWE-SKT", firmware_version="3.02")
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.homewizard.coordinator.HomeWizardEnergy",
|
||||
return_value=api,
|
||||
):
|
||||
entry = mock_config_entry
|
||||
entry.data = mock_config_entry_data
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
hass.states.get("button.product_name_aabbccddeeff_identify").state
|
||||
== STATE_UNKNOWN
|
||||
)
|
||||
|
||||
assert api.identify.call_count == 0
|
||||
await hass.services.async_call(
|
||||
button.DOMAIN,
|
||||
button.SERVICE_PRESS,
|
||||
{"entity_id": "button.product_name_aabbccddeeff_identify"},
|
||||
blocking=True,
|
||||
)
|
||||
assert api.identify.call_count == 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user