1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Simplify esphome (#22868)

* Add ESPHome climate support

* Adjust line length

* Update .coveragerc

* Update climate.py

* Simplify esphome integration

* Undo change

* Update cover.py
This commit is contained in:
Otto Winter
2019-04-16 22:48:46 +02:00
committed by Paulus Schoutsen
parent 10e8f4f70a
commit 3186109172
9 changed files with 113 additions and 135 deletions

View File

@@ -11,7 +11,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType
import homeassistant.util.color as color_util
from . import EsphomeEntity, platform_async_setup_entry
from . import EsphomeEntity, platform_async_setup_entry, esphome_state_property
if TYPE_CHECKING:
# pylint: disable=unused-import
@@ -51,11 +51,9 @@ class EsphomeLight(EsphomeEntity, Light):
def _state(self) -> Optional['LightState']:
return super()._state
@property
@esphome_state_property
def is_on(self) -> Optional[bool]:
"""Return true if the switch is on."""
if self._state is None:
return None
return self._state.state
async def async_turn_on(self, **kwargs) -> None:
@@ -88,42 +86,32 @@ class EsphomeLight(EsphomeEntity, Light):
data['transition_length'] = kwargs[ATTR_TRANSITION]
await self._client.light_command(**data)
@property
@esphome_state_property
def brightness(self) -> Optional[int]:
"""Return the brightness of this light between 0..255."""
if self._state is None:
return None
return round(self._state.brightness * 255)
@property
@esphome_state_property
def hs_color(self) -> Optional[Tuple[float, float]]:
"""Return the hue and saturation color value [float, float]."""
if self._state is None:
return None
return color_util.color_RGB_to_hs(
self._state.red * 255,
self._state.green * 255,
self._state.blue * 255)
@property
@esphome_state_property
def color_temp(self) -> Optional[float]:
"""Return the CT color value in mireds."""
if self._state is None:
return None
return self._state.color_temperature
@property
@esphome_state_property
def white_value(self) -> Optional[int]:
"""Return the white value of this light between 0..255."""
if self._state is None:
return None
return round(self._state.white * 255)
@property
@esphome_state_property
def effect(self) -> Optional[str]:
"""Return the current effect."""
if self._state is None:
return None
return self._state.effect
@property