From 64a13698f2e21d2877b0fbe3c5fda657b00ffe63 Mon Sep 17 00:00:00 2001 From: YeonV Date: Thu, 12 Nov 2020 22:09:54 +0100 Subject: [PATCH] v0.0.9 --- README.md | 4 +++- custom_components/ledfxrm/__init__.py | 17 +++++++++++------ custom_components/ledfxrm/const.py | 2 +- custom_components/ledfxrm/light.py | 18 +++++++++++------- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2f0fc83..383baef 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,9 @@ A picklist is created/upadted and filled with the scenes [Frenck](https://github.com/frenck) -[Tinkerer](https://github.com/DubhAd/) +[On](https://github.com/OnFreund) + +[Tinkerer](https://github.com/DubhAd) https://github.com/ahodges9/LedFx/tree/dev/ledfx diff --git a/custom_components/ledfxrm/__init__.py b/custom_components/ledfxrm/__init__.py index b06f5d7..a4e2106 100644 --- a/custom_components/ledfxrm/__init__.py +++ b/custom_components/ledfxrm/__init__.py @@ -9,6 +9,8 @@ from homeassistant.core import Config, HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed +from homeassistant import bootstrap + from custom_components.ledfxrm.const import ( DOMAIN, @@ -40,7 +42,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): theversion = entry.data.get('version') thestart = entry.data.get('start') thestop = entry.data.get('stop') - + coordinator = LedfxrmDataUpdateCoordinator( hass, thehost, theport, theversion, thestart, thestop ) @@ -61,6 +63,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): return True + class myClient(): def __init__(self, thehost, theport, thestart, thestop): self.thehost = thehost @@ -68,6 +71,7 @@ def __init__(self, thehost, theport, thestart, thestop): self.thestart = thestart self.thestop = thestop self.connected = False + self.effect = 'off' async def update(self): url = "http://" + self.thehost + ":" + str(self.theport) + "/api/info" @@ -96,7 +100,6 @@ async def update(self): return {'info':rest_info, 'devices': rest_devices, 'scenes': rest_scenes} async def async_change_something(self, state): - logging.warning('STATE CHANGE: %s', state) if state is True: logging.warning('Start Button will soon do: %s', self.thestart) self.connected = True @@ -109,11 +112,12 @@ async def async_change_something(self, state): async def async_set_scene(self, effect): if effect is None: return - logging.warning('Setting Scene to %s', effect) url3 = "http://" + self.thehost + ":" + str(self.theport) + "/api/scenes" - async with session.put(url3, json={"id": effect, "action": "activate"}, ssl=False) as resp_scenes: - res_set_scene = await resp_scenes.json() - logging.warning('Set Scene to %s', res_set_scene) + loop = asyncio.get_event_loop() + async with aiohttp.ClientSession(loop=loop, trust_env = True) as session: + async with session.put(url3, json={"id": effect, "action": "activate"}, ssl=False) as resp_scenes: + res_set_scene = await resp_scenes.json() + self.effect = effect return None class LedfxrmDataUpdateCoordinator(DataUpdateCoordinator): @@ -135,6 +139,7 @@ async def _async_update_data(self): data = await self.api.update() scenes = data.get('scenes').get('scenes') self.scenes = scenes + self.number_scenes = len(scenes) return data except Exception as exception: diff --git a/custom_components/ledfxrm/const.py b/custom_components/ledfxrm/const.py index b874ddc..eeb1762 100644 --- a/custom_components/ledfxrm/const.py +++ b/custom_components/ledfxrm/const.py @@ -3,7 +3,7 @@ NAME = "LedFX ReMote" DOMAIN = "ledfxrm" DOMAIN_DATA = f"{DOMAIN}_data" -VERSION = "0.0.8" +VERSION = "0.0.9" MANUFACTURER = "YeonV" ISSUE_URL = "https://github.com/YeonV/ledfxrm/issues" diff --git a/custom_components/ledfxrm/light.py b/custom_components/ledfxrm/light.py index 25865b5..66e84c1 100644 --- a/custom_components/ledfxrm/light.py +++ b/custom_components/ledfxrm/light.py @@ -17,6 +17,11 @@ class LedfxrmBinaryLight(LedfxrmEntity, LightEntity): async def async_turn_on(self, **kwargs): # pylint: disable=unused-argument """Turn on the switch.""" + if ATTR_EFFECT in kwargs: + await self.coordinator.api.async_set_scene(kwargs['effect']) + await self.coordinator.async_request_refresh() + return True + await self.coordinator.api.async_change_something(True) await self.coordinator.async_request_refresh() @@ -26,13 +31,7 @@ async def async_turn_off(self, **kwargs): # pylint: disable=unused-argument await self.coordinator.api.async_change_something(False) await self.coordinator.async_request_refresh() - async def async_set_effect(self, effect): - """Activate effect.""" - logging.warning('EFFECT SELECTED: %s', effect) - if not effect: - return - - await self.coordinator.api.async_set_scene(effect) + @property def supported_features(self) -> int: @@ -53,6 +52,11 @@ def name(self): def icon(self): """Return the icon of this light.""" return ICON_ASCENE + + @property + def effect(self): + """Return the current effect.""" + return self.coordinator.api.effect @property def effect_list(self):