mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Add health mode to gree integration (#89764)
Add health mode to gree integration.
This commit is contained in:
parent
1e64a55a1a
commit
b151923619
@ -26,6 +26,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
GreePanelLightSwitchEntity(coordinator),
|
GreePanelLightSwitchEntity(coordinator),
|
||||||
|
GreeHealthModeSwitchEntity(coordinator),
|
||||||
GreeQuietModeSwitchEntity(coordinator),
|
GreeQuietModeSwitchEntity(coordinator),
|
||||||
GreeFreshAirSwitchEntity(coordinator),
|
GreeFreshAirSwitchEntity(coordinator),
|
||||||
GreeXFanSwitchEntity(coordinator),
|
GreeXFanSwitchEntity(coordinator),
|
||||||
@ -75,6 +76,42 @@ class GreePanelLightSwitchEntity(GreeEntity, SwitchEntity):
|
|||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
|
class GreeHealthModeSwitchEntity(GreeEntity, SwitchEntity):
|
||||||
|
"""Representation of the health mode on the device."""
|
||||||
|
|
||||||
|
def __init__(self, coordinator):
|
||||||
|
"""Initialize the Gree device."""
|
||||||
|
super().__init__(coordinator, "Health mode")
|
||||||
|
self._attr_entity_registry_enabled_default = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self) -> str | None:
|
||||||
|
"""Return the icon for the device."""
|
||||||
|
return "mdi:pine-tree"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||||
|
return SwitchDeviceClass.SWITCH
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self) -> bool:
|
||||||
|
"""Return if the health mode is turned on."""
|
||||||
|
return self.coordinator.device.anion
|
||||||
|
|
||||||
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
|
"""Turn the entity on."""
|
||||||
|
self.coordinator.device.anion = True
|
||||||
|
await self.coordinator.push_state_update()
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
|
"""Turn the entity off."""
|
||||||
|
self.coordinator.device.anion = False
|
||||||
|
await self.coordinator.push_state_update()
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
class GreeQuietModeSwitchEntity(GreeEntity, SwitchEntity):
|
class GreeQuietModeSwitchEntity(GreeEntity, SwitchEntity):
|
||||||
"""Representation of the quiet mode state of the device."""
|
"""Representation of the quiet mode state of the device."""
|
||||||
|
|
||||||
|
@ -14,11 +14,13 @@ from homeassistant.const import (
|
|||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
ENTITY_ID_LIGHT_PANEL = f"{DOMAIN}.fake_device_1_panel_light"
|
ENTITY_ID_LIGHT_PANEL = f"{DOMAIN}.fake_device_1_panel_light"
|
||||||
|
ENTITY_ID_HEALTH_MODE = f"{DOMAIN}.fake_device_1_health_mode"
|
||||||
ENTITY_ID_QUIET = f"{DOMAIN}.fake_device_1_quiet"
|
ENTITY_ID_QUIET = f"{DOMAIN}.fake_device_1_quiet"
|
||||||
ENTITY_ID_FRESH_AIR = f"{DOMAIN}.fake_device_1_fresh_air"
|
ENTITY_ID_FRESH_AIR = f"{DOMAIN}.fake_device_1_fresh_air"
|
||||||
ENTITY_ID_XFAN = f"{DOMAIN}.fake_device_1_xfan"
|
ENTITY_ID_XFAN = f"{DOMAIN}.fake_device_1_xfan"
|
||||||
@ -31,16 +33,29 @@ async def async_setup_gree(hass):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_health_mode_disabled_by_default(hass):
|
||||||
|
"""Test for making sure health mode is disabled on first load."""
|
||||||
|
await async_setup_gree(hass)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
er.async_get(hass).async_get(ENTITY_ID_HEALTH_MODE).disabled_by
|
||||||
|
== er.RegistryEntryDisabler.INTEGRATION
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"entity",
|
"entity",
|
||||||
[
|
[
|
||||||
ENTITY_ID_LIGHT_PANEL,
|
ENTITY_ID_LIGHT_PANEL,
|
||||||
|
ENTITY_ID_HEALTH_MODE,
|
||||||
ENTITY_ID_QUIET,
|
ENTITY_ID_QUIET,
|
||||||
ENTITY_ID_FRESH_AIR,
|
ENTITY_ID_FRESH_AIR,
|
||||||
ENTITY_ID_XFAN,
|
ENTITY_ID_XFAN,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_send_switch_on(hass: HomeAssistant, entity) -> None:
|
async def test_send_switch_on(
|
||||||
|
hass: HomeAssistant, entity, entity_registry_enabled_by_default
|
||||||
|
) -> None:
|
||||||
"""Test for sending power on command to the device."""
|
"""Test for sending power on command to the device."""
|
||||||
await async_setup_gree(hass)
|
await async_setup_gree(hass)
|
||||||
|
|
||||||
@ -60,13 +75,14 @@ async def test_send_switch_on(hass: HomeAssistant, entity) -> None:
|
|||||||
"entity",
|
"entity",
|
||||||
[
|
[
|
||||||
ENTITY_ID_LIGHT_PANEL,
|
ENTITY_ID_LIGHT_PANEL,
|
||||||
|
ENTITY_ID_HEALTH_MODE,
|
||||||
ENTITY_ID_QUIET,
|
ENTITY_ID_QUIET,
|
||||||
ENTITY_ID_FRESH_AIR,
|
ENTITY_ID_FRESH_AIR,
|
||||||
ENTITY_ID_XFAN,
|
ENTITY_ID_XFAN,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_send_switch_on_device_timeout(
|
async def test_send_switch_on_device_timeout(
|
||||||
hass: HomeAssistant, device, entity
|
hass: HomeAssistant, device, entity, entity_registry_enabled_by_default
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for sending power on command to the device with a device timeout."""
|
"""Test for sending power on command to the device with a device timeout."""
|
||||||
device().push_state_update.side_effect = DeviceTimeoutError
|
device().push_state_update.side_effect = DeviceTimeoutError
|
||||||
@ -89,12 +105,15 @@ async def test_send_switch_on_device_timeout(
|
|||||||
"entity",
|
"entity",
|
||||||
[
|
[
|
||||||
ENTITY_ID_LIGHT_PANEL,
|
ENTITY_ID_LIGHT_PANEL,
|
||||||
|
ENTITY_ID_HEALTH_MODE,
|
||||||
ENTITY_ID_QUIET,
|
ENTITY_ID_QUIET,
|
||||||
ENTITY_ID_FRESH_AIR,
|
ENTITY_ID_FRESH_AIR,
|
||||||
ENTITY_ID_XFAN,
|
ENTITY_ID_XFAN,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_send_switch_off(hass: HomeAssistant, entity) -> None:
|
async def test_send_switch_off(
|
||||||
|
hass: HomeAssistant, entity, entity_registry_enabled_by_default
|
||||||
|
) -> None:
|
||||||
"""Test for sending power on command to the device."""
|
"""Test for sending power on command to the device."""
|
||||||
await async_setup_gree(hass)
|
await async_setup_gree(hass)
|
||||||
|
|
||||||
@ -114,12 +133,15 @@ async def test_send_switch_off(hass: HomeAssistant, entity) -> None:
|
|||||||
"entity",
|
"entity",
|
||||||
[
|
[
|
||||||
ENTITY_ID_LIGHT_PANEL,
|
ENTITY_ID_LIGHT_PANEL,
|
||||||
|
ENTITY_ID_HEALTH_MODE,
|
||||||
ENTITY_ID_QUIET,
|
ENTITY_ID_QUIET,
|
||||||
ENTITY_ID_FRESH_AIR,
|
ENTITY_ID_FRESH_AIR,
|
||||||
ENTITY_ID_XFAN,
|
ENTITY_ID_XFAN,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_send_switch_toggle(hass: HomeAssistant, entity) -> None:
|
async def test_send_switch_toggle(
|
||||||
|
hass: HomeAssistant, entity, entity_registry_enabled_by_default
|
||||||
|
) -> None:
|
||||||
"""Test for sending power on command to the device."""
|
"""Test for sending power on command to the device."""
|
||||||
await async_setup_gree(hass)
|
await async_setup_gree(hass)
|
||||||
|
|
||||||
@ -164,12 +186,15 @@ async def test_send_switch_toggle(hass: HomeAssistant, entity) -> None:
|
|||||||
("entity", "name"),
|
("entity", "name"),
|
||||||
[
|
[
|
||||||
(ENTITY_ID_LIGHT_PANEL, "Panel Light"),
|
(ENTITY_ID_LIGHT_PANEL, "Panel Light"),
|
||||||
|
(ENTITY_ID_HEALTH_MODE, "Health mode"),
|
||||||
(ENTITY_ID_QUIET, "Quiet"),
|
(ENTITY_ID_QUIET, "Quiet"),
|
||||||
(ENTITY_ID_FRESH_AIR, "Fresh Air"),
|
(ENTITY_ID_FRESH_AIR, "Fresh Air"),
|
||||||
(ENTITY_ID_XFAN, "XFan"),
|
(ENTITY_ID_XFAN, "XFan"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_entity_name(hass: HomeAssistant, entity, name) -> None:
|
async def test_entity_name(
|
||||||
|
hass: HomeAssistant, entity, name, entity_registry_enabled_by_default
|
||||||
|
) -> None:
|
||||||
"""Test for name property."""
|
"""Test for name property."""
|
||||||
await async_setup_gree(hass)
|
await async_setup_gree(hass)
|
||||||
state = hass.states.get(entity)
|
state = hass.states.get(entity)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user