Various light test improvements (#34131)

This commit is contained in:
Franck Nijhof authored and GitHub committed 2020-04-13 15:33:04 +02:00
1 parent 4bcceb4078
commit 6d24a65313
7 files changed
+418 -259

No files matched your search

+5 -8
View File
@@ -84,10 +84,7 @@ class DemoLight(Light):
self._effect_list = effect_list
self._effect = effect
self._available = True
if ct is not None and hs_color is None:
self._color_mode = "ct"
else:
self._color_mode = "hs"
self._color_mode = "ct" if ct is not None and hs_color is None else "hs"
@property
def device_info(self):
@@ -166,7 +163,7 @@ class DemoLight(Light):
"""Flag supported features."""
return SUPPORT_DEMO
def turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs) -> None:
"""Turn the light on."""
self._state = True
@@ -189,12 +186,12 @@ class DemoLight(Light):
# As we have disabled polling, we need to inform
# Home Assistant about updates in our state ourselves.
self.schedule_update_ha_state()
self.async_write_ha_state()
def turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs) -> None:
"""Turn the light off."""
self._state = False
# As we have disabled polling, we need to inform
# Home Assistant about updates in our state ourselves.
self.schedule_update_ha_state()
self.async_write_ha_state()
+5 -5
View File
@@ -191,11 +191,11 @@ async def async_setup(hass, config):
def preprocess_data(data):
"""Preprocess the service data."""
base = {}
for entity_field in cv.ENTITY_SERVICE_FIELDS:
if entity_field in data:
base[entity_field] = data.pop(entity_field)
base = {
entity_field: data.pop(entity_field)
for entity_field in cv.ENTITY_SERVICE_FIELDS
if entity_field in data
}
preprocess_turn_on_alternatives(data)
turn_lights_off, off_params = preprocess_turn_off(data)
+3 -7
View File
@@ -319,11 +319,7 @@ class Entity(ABC):
else:
state = self.state
if state is None:
state = STATE_UNKNOWN
else:
state = str(state)
state = STATE_UNKNOWN if state is None else str(state)
attr.update(self.state_attributes or {})
attr.update(self.device_state_attributes or {})
@@ -622,7 +618,7 @@ class ToggleEntity(Entity):
async def async_turn_on(self, **kwargs):
"""Turn the entity on."""
await self.hass.async_add_job(ft.partial(self.turn_on, **kwargs))
await self.hass.async_add_executor_job(ft.partial(self.turn_on, **kwargs))
def turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
@@ -630,7 +626,7 @@ class ToggleEntity(Entity):
async def async_turn_off(self, **kwargs):
"""Turn the entity off."""
await self.hass.async_add_job(ft.partial(self.turn_off, **kwargs))
await self.hass.async_add_executor_job(ft.partial(self.turn_off, **kwargs))
def toggle(self, **kwargs: Any) -> None:
"""Toggle the entity."""