-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for lights (on/off).
- Loading branch information
Showing
5 changed files
with
63 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Light platform for MyGekko.""" | ||
from homeassistant.core import callback | ||
from homeassistant.components.light import LightEntity, ColorMode | ||
from PyMyGekko.resources.Lights import Light, LightState | ||
|
||
from .const import DOMAIN, LIGHT | ||
from .entity import MyGekkoEntity | ||
|
||
|
||
async def async_setup_entry(hass, entry, async_add_devices): | ||
"""Setup light platform.""" | ||
coordinator = hass.data[DOMAIN][entry.entry_id] | ||
lights = coordinator.api.get_lights() | ||
print(lights) | ||
if lights is not None: | ||
async_add_devices(MyGekkoLight(coordinator, light) for light in lights) | ||
|
||
|
||
class MyGekkoLight(MyGekkoEntity, LightEntity): | ||
"""mygekko Light class.""" | ||
|
||
|
||
def __init__(self, coordinator, light: Light): | ||
super().__init__(coordinator, light, LIGHT) | ||
print(light.id, light.name) | ||
self._light = light | ||
self._attr_supported_color_modes = set() | ||
self._attr_supported_color_modes.add(ColorMode.ONOFF) | ||
self._attr_color_mode = ColorMode.ONOFF | ||
|
||
|
||
@callback | ||
def _handle_coordinator_update(self) -> None: | ||
"""Handle updated data from the coordinator.""" | ||
self.async_write_ha_state() | ||
|
||
def is_on(self) -> bool | None: | ||
return self._light.state == LightState.ON | ||
|
||
async def async_turn_off(self, **kwargs): | ||
await self._light.set_state(LightState.OFF) | ||
|
||
async def async_turn_on(self, **kwargs): | ||
await self._light.set_state(LightState.ON) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters