Skip to content

Commit

Permalink
v0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Nov 12, 2020
1 parent 9ac097b commit 64a1369
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 11 additions & 6 deletions custom_components/ledfxrm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
)
Expand All @@ -61,13 +63,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
return True



class myClient():
def __init__(self, thehost, theport, thestart, thestop):
self.thehost = thehost
self.theport = theport
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"
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ledfxrm/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 11 additions & 7 deletions custom_components/ledfxrm/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 64a1369

Please sign in to comment.