core/homeassistant/components/gree/switch.py

155 lines
4.4 KiB
Python
Raw Normal View History

"""Support for interface with a Gree climate systems."""
2021-03-18 07:02:55 +00:00
from __future__ import annotations
2023-03-27 08:00:41 +00:00
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any
2022-08-26 09:37:12 +00:00
2023-03-27 08:00:41 +00:00
from greeclimate.device import Device
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
from homeassistant.components.switch import (
SwitchDeviceClass,
SwitchEntity,
SwitchEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import COORDINATORS, DISPATCH_DEVICE_DISCOVERED, DISPATCHERS, DOMAIN
from .entity import GreeEntity
2023-03-27 08:00:41 +00:00
@dataclass
class GreeRequiredKeysMixin:
"""Mixin for required keys."""
get_value_fn: Callable[[Device], bool]
set_value_fn: Callable[[Device, bool], None]
@dataclass
class GreeSwitchEntityDescription(SwitchEntityDescription, GreeRequiredKeysMixin):
"""Describes Gree switch entity."""
# GreeSwitch does not support UNDEFINED or None,
# restrict the type to str.
name: str = ""
2023-03-27 08:00:41 +00:00
def _set_light(device: Device, value: bool) -> None:
"""Typed helper to set device light property."""
device.light = value
def _set_quiet(device: Device, value: bool) -> None:
"""Typed helper to set device quiet property."""
device.quiet = value
def _set_fresh_air(device: Device, value: bool) -> None:
"""Typed helper to set device fresh_air property."""
device.fresh_air = value
def _set_xfan(device: Device, value: bool) -> None:
"""Typed helper to set device xfan property."""
device.xfan = value
def _set_anion(device: Device, value: bool) -> None:
"""Typed helper to set device anion property."""
device.anion = value
GREE_SWITCHES: tuple[GreeSwitchEntityDescription, ...] = (
GreeSwitchEntityDescription(
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
icon="mdi:lightbulb",
name="Panel Light",
key="light",
2023-03-27 08:00:41 +00:00
get_value_fn=lambda d: d.light,
set_value_fn=_set_light,
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
),
2023-03-27 08:00:41 +00:00
GreeSwitchEntityDescription(
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
name="Quiet",
key="quiet",
2023-03-27 08:00:41 +00:00
get_value_fn=lambda d: d.quiet,
set_value_fn=_set_quiet,
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
),
2023-03-27 08:00:41 +00:00
GreeSwitchEntityDescription(
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
name="Fresh Air",
key="fresh_air",
2023-03-27 08:00:41 +00:00
get_value_fn=lambda d: d.fresh_air,
set_value_fn=_set_fresh_air,
),
GreeSwitchEntityDescription(
name="XFan",
key="xfan",
get_value_fn=lambda d: d.xfan,
set_value_fn=_set_xfan,
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
),
2023-03-27 08:00:41 +00:00
GreeSwitchEntityDescription(
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
icon="mdi:pine-tree",
name="Health mode",
key="anion",
2023-03-27 08:00:41 +00:00
get_value_fn=lambda d: d.anion,
set_value_fn=_set_anion,
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
entity_registry_enabled_default=False,
),
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Gree HVAC device from a config entry."""
@callback
def init_device(coordinator):
"""Register the device."""
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
async_add_entities(
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
GreeSwitch(coordinator=coordinator, description=description)
for description in GREE_SWITCHES
)
for coordinator in hass.data[DOMAIN][COORDINATORS]:
init_device(coordinator)
hass.data[DOMAIN][DISPATCHERS].append(
async_dispatcher_connect(hass, DISPATCH_DEVICE_DISCOVERED, init_device)
)
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
class GreeSwitch(GreeEntity, SwitchEntity):
"""Generic Gree switch entity."""
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
_attr_device_class = SwitchDeviceClass.SWITCH
2023-03-27 08:00:41 +00:00
entity_description: GreeSwitchEntityDescription
2023-03-27 08:00:41 +00:00
def __init__(self, coordinator, description: GreeSwitchEntityDescription) -> None:
"""Initialize the Gree device."""
Refactor Gree switch to use EntityDescription (#90143) * Post-rebase * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * feat: Tests passing! * Removing custom attributes as no longer needed * removed extraneous class * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/gree/switch.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> * Update tests/components/gree/test_switch.py Co-authored-by: solazs <soltesz.balazs.91@gmail.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: solazs <soltesz.balazs.91@gmail.com>
2023-03-25 08:15:46 +00:00
self.entity_description = description
super().__init__(coordinator, description.name)
@property
def is_on(self) -> bool:
"""Return if the state is turned on."""
2023-03-27 08:00:41 +00:00
return self.entity_description.get_value_fn(self.coordinator.device)
2022-08-26 09:37:12 +00:00
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on."""
2023-03-27 08:00:41 +00:00
self.entity_description.set_value_fn(self.coordinator.device, True)
await self.coordinator.push_state_update()
self.async_write_ha_state()
2022-08-26 09:37:12 +00:00
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
2023-03-27 08:00:41 +00:00
self.entity_description.set_value_fn(self.coordinator.device, False)
await self.coordinator.push_state_update()
self.async_write_ha_state()