Skip to content

Commit

Permalink
v0.2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed May 18, 2021
1 parent 0815145 commit 6070759
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 137 deletions.
112 changes: 56 additions & 56 deletions custom_components/ledfxrm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
thestart = entry.data.get(CONF_START)
thestop = entry.data.get(CONF_STOP)
thescan = entry.data.get(CONF_SCAN_INTERVAL)
thesubdevices = entry.data.get(CONF_SHOW_SUBDEVICES)
thesubdisplays = entry.data.get(CONF_SHOW_SUBDEVICES)
theblade_light = entry.data.get(CONF_SHOW_BLADELIGHT)
thestart_method = entry.data.get(CONF_START_METHOD)
thestart_body = entry.data.get(CONF_START_BODY)
Expand All @@ -78,7 +78,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
thestart,
thestop,
thescan,
thesubdevices,
thesubdisplays,
theblade_light,
thestart_method,
thestart_body,
Expand Down Expand Up @@ -113,7 +113,7 @@ def __init__(
theport,
thestart,
thestop,
thesubdevices,
thesubdisplays,
theblade_light,
thestart_method,
thestart_body,
Expand All @@ -126,10 +126,10 @@ def __init__(
self.thestop = thestop
self.connected = False
self.effect = "off"
self.thesubdevices = thesubdevices
self.thesubdisplays = thesubdisplays
self.theblade_light = theblade_light
self.devicestates = {}
self.devices = {}
self.displaystates = {}
self.displays = {}
self.virtuals = {}
self.thestart_method = thestart_method
self.thestart_body = thestart_body
Expand All @@ -144,11 +144,11 @@ async def update(self):
url4 = "http://" + self.thehost + ":" + str(self.theport) + "/api/virtuals"
yz = {}
rest_info = {}
rest_devices = {}
rest_displays = {}
rest_scenes = {}
rest_virtuals = {}
yz["rest_info"] = {}
yz["rest_devices"] = {}
yz["rest_displays"] = {}
yz["rest_scenes"] = {}
yz["rest_virtuals"] = {}

Expand All @@ -170,30 +170,30 @@ async def update(self):
return {}

try:
async with session.get(url2, ssl=False) as resp_devices:
if resp_devices.status == 200:
rest_devices = await resp_devices.json()
yz["rest_devices"] = rest_devices
self.devices = yz["rest_devices"]
if len(self.devicestates) == 0:
for k in rest_devices["displays"]:
async with session.get(url2, ssl=False) as resp_displays:
if resp_displays.status == 200:
rest_displays = await resp_displays.json()
yz["rest_displays"] = rest_displays
self.displays = yz["rest_displays"]
if len(self.displaystates) == 0:
for k in rest_displays["displays"]:
if (
len(rest_devices["displays"][k].get("effect", {}))
len(rest_displays["displays"][k].get("effect", {}))
> 0
):
effect = rest_devices["displays"][k].get("effect")
effect = rest_displays["displays"][k].get("effect")
power = True
else:

effect = {}
power = False
self.devicestates[k] = {
self.displaystates[k] = {
"power": power,
"effect": effect,
}
else:
logging.warning(
"CANT CONNECT TO LEDFX - DEVICES: %s", resp_devices.status
"CANT CONNECT TO LEDFX - DEVICES: %s", resp_displays.status
)

except aiohttp.ClientConnectorError as e:
Expand Down Expand Up @@ -230,28 +230,28 @@ async def update(self):
# rest_info = await resp.json()
# yz["rest_info"] = rest_info

# async with session.get(url2, ssl=False) as resp_devices:
# rest_devices = await resp_devices.json()
# yz["rest_devices"] = rest_devices
# self.devices = yz["rest_devices"]
# # logging.warning("INTERNAL STATES b4: %s", self.devicestates)
# if len(self.devicestates) == 0:
# for k in rest_devices["devices"]:
# async with session.get(url2, ssl=False) as resp_displays:
# rest_displays = await resp_displays.json()
# yz["rest_displays"] = rest_displays
# self.displays = yz["rest_displays"]
# # logging.warning("INTERNAL STATES b4: %s", self.displaystates)
# if len(self.displaystates) == 0:
# for k in rest_displays["displays"]:
# # logging.warning("NOWWW: %s", k)
# # logging.warning("THENN: %s", rest_devices['devices'][k])
# if len(rest_devices["devices"][k].get("effect", {})) > 0:
# # logging.warning("GOT EFFECT FROM LEDFX: %s", rest_devices['devices'][k].get('effect'))
# effect = rest_devices["devices"][k].get("effect")
# # logging.warning("THENN: %s", rest_displays['displays'][k])
# if len(rest_displays["displays"][k].get("effect", {})) > 0:
# # logging.warning("GOT EFFECT FROM LEDFX: %s", rest_displays['displays'][k].get('effect'))
# effect = rest_displays["displays"][k].get("effect")
# power = True
# else:

# effect = {}
# power = False
# self.devicestates[k] = {
# self.displaystates[k] = {
# "power": power,
# "effect": effect, # self.devicestates[k].get('effect', {})
# "effect": effect, # self.displaystates[k].get('effect', {})
# }
# # logging.warning("INTERNAL STATES after: %s", self.devicestates)
# # logging.warning("INTERNAL STATES after: %s", self.displaystates)

# async with session.get(url3, ssl=False) as resp_scenes:
# rest_scenes = await resp_scenes.json()
Expand All @@ -262,10 +262,10 @@ async def update(self):

return {
"info": rest_info,
"devices": rest_devices,
"displays": rest_displays,
"virtuals": rest_virtuals,
"scenes": rest_scenes,
"show_subdevices": self.thesubdevices,
"show_subdisplays": self.thesubdisplays,
}

async def async_set_transition_time(self, time):
Expand Down Expand Up @@ -345,13 +345,13 @@ async def async_set_scene(self, effect):
return None

async def async_device_off(self, state):
# logging.warning('DEVICE OFF internal --- %s --- %s', state, self.devicestates[state].get('effect'))
# logging.warning('DEVICE OFF internal --- %s --- %s', state, self.displaystates[state].get('effect'))
url4 = (
"http://"
+ self.thehost
+ ":"
+ str(self.theport)
+ "/api/devices/"
+ "/api/displays/"
+ state
+ "/effects"
)
Expand All @@ -361,24 +361,24 @@ async def async_device_off(self, state):
async with session.get(url4, ssl=False) as get_effect:
testing = await get_effect.json()
if testing["effect"] != {}:
self.devicestates[state]["effect"] = testing["effect"]
# logging.warning("Turning Off, found effect: %s", self.devicestates[state].get('effect'))
self.displaystates[state]["effect"] = testing["effect"]
# logging.warning("Turning Off, found effect: %s", self.displaystates[state].get('effect'))
async with session.delete(url4, ssl=False) as del_effect:
await del_effect.json()
# else:
# logging.warning("Turning Off, No effect:")

self.devicestates[state]["power"] = False
self.displaystates[state]["power"] = False
return None

async def async_device_on(self, state):
# logging.warning('DEVICE ON internal --- %s --- %s', state, self.devicestates[state].get('effect'))
# logging.warning('DEVICE ON internal --- %s --- %s', state, self.displaystates[state].get('effect'))
url4 = (
"http://"
+ self.thehost
+ ":"
+ str(self.theport)
+ "/api/devices/"
+ "/api/displays/"
+ state
+ "/effects"
)
Expand All @@ -389,10 +389,10 @@ async def async_device_on(self, state):
testing = await get_effect.json()
if testing["effect"] != {}:
# logging.warning("Turning on, found effect: %s", testing['effect'])
self.devicestates[state]["effect"] = testing["effect"]
self.displaystates[state]["effect"] = testing["effect"]

# payload = {'config': self.devicestates[state].get('effect').get('config')}
payload = self.devicestates[state].get("effect")
# payload = {'config': self.displaystates[state].get('effect').get('config')}
payload = self.displaystates[state].get("effect")

if payload is None or payload == {}:
payload = {
Expand All @@ -416,7 +416,7 @@ async def async_device_on(self, state):
# logging.warning("Setting Effect, %s", payload)
async with session.post(url4, json=payload, ssl=False) as set_effect:
await set_effect.json()
self.devicestates[state]["power"] = True
self.displaystates[state]["power"] = True
return None

async def async_virtual_off(self, virtual):
Expand All @@ -430,9 +430,9 @@ async def async_virtual_off(self, virtual):
for key in c:
# logging.warning(
# "BLADE OFF internal --- %s --- %s --- %s",
# self.devices.get("devices").get(key).get("config").get("name"),
# self.devices.get("devices").get(key).get("config").get("ip_address"),
# self.devices.get("devices").get(key).get("config").get("pixel_count"),
# self.displays.get("displays").get(key).get("config").get("name"),
# self.displays.get("displays").get(key).get("config").get("ip_address"),
# self.displays.get("displays").get(key).get("config").get("pixel_count"),
# )
for i in range(key.get("used_pixel")):

Expand Down Expand Up @@ -521,7 +521,7 @@ def __init__(
theblade_light,
thestop,
thescan,
thesubdevices,
thesubdisplays,
thestart_method,
thestart_body,
thestop_method,
Expand All @@ -535,7 +535,7 @@ def __init__(
self.thestop = thestop
self.thestart = thestart
self.thescan = thescan
self.thesubdevices = thesubdevices
self.thesubdisplays = thesubdisplays
self.theblade_light = theblade_light
self.thestart_method = thestart_method
self.thestart_body = thestart_body
Expand All @@ -547,7 +547,7 @@ def __init__(
theport,
thestart,
thestop,
thesubdevices,
thesubdisplays,
theblade_light,
thestart_method,
thestart_body,
Expand All @@ -564,17 +564,17 @@ async def _async_update_data(self):
# logging.warning('SCAN_INTERVAL_CHECK %s', self.thescan)
data = await self.api.update()
scenes = {}
devices = {}
displays = {}
virtuals = {}
# logging.warning("UPDATING %s", data)
if data != {}:

scenes = data.get("scenes").get("scenes")
devices = data.get("devices").get("devices")
displays = data.get("displays").get("displays")
if scenes != {}:
# logging.warning("UPDATING WTF %s", data)
self.scenes = scenes
self.devices = devices
self.displays = displays
self.number_scenes = len(scenes)
self.lost = False
self.connected = True
Expand Down Expand Up @@ -605,7 +605,7 @@ async def _async_update_data(self):
return {
"info": {"name": "Not Ready", "version": "1.0"},
"scenes": {"scenes": {}},
"devices": {"devices": {}},
"displays": {"displays": {}},
"virtuals": {"virtuals": {}},
}

Expand Down
4 changes: 2 additions & 2 deletions custom_components/ledfxrm/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from custom_components.ledfxrm.entity import LedfxrmEntity


async def async_setup_entry(hass, entry, async_add_devices):
async def async_setup_entry(hass, entry, async_add_displays):
"""Setup binary_sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices([LedfxrmBinarySensor(coordinator, entry)])
async_add_displays([LedfxrmBinarySensor(coordinator, entry)])


class LedfxrmBinarySensor(LedfxrmEntity, BinarySensorEntity ):
Expand Down
4 changes: 2 additions & 2 deletions 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.2.6"
VERSION = "0.2.9"
MANUFACTURER = "YeonV"

ISSUE_URL = "https://github.com/YeonV/ledfxrm/issues"
Expand Down Expand Up @@ -37,7 +37,7 @@
CONF_STOP = "stop"
CONF_ADVANCED = "advanced"
CONF_SCAN_INTERVAL = "scan_interval"
CONF_SHOW_SUBDEVICES = "show_subdevices"
CONF_SHOW_SUBDEVICES = "show_subdisplays"
CONF_SHOW_BLADELIGHT = "show_blade_light"
CONF_START_METHOD = "start_method"
CONF_STOP_METHOD = "stop_method"
Expand Down
22 changes: 11 additions & 11 deletions custom_components/ledfxrm/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@
from typing import Any, Dict, Optional


async def async_setup_entry(hass, entry, async_add_devices):
async def async_setup_entry(hass, entry, async_add_displays):
"""Setup sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
devicenames = coordinator.data.get("devices").get("devices")
devicenames = coordinator.data.get("displays").get("displays")
virtuals = coordinator.data.get("virtuals").get("virtuals").get("list")
# logging.warning("YEEES2: %s", virtuals)
test = entry.data.get(CONF_SHOW_SUBDEVICES)
test2 = entry.data.get(CONF_SHOW_BLADELIGHT)
if test is True:
for k in devicenames:
async_add_devices(
async_add_displays(
[LedfxrmChildLight(coordinator, entry, k, devicenames[k]["config"])]
)

if test2 is True:
async_add_devices([LedfxrmLight(coordinator, entry)])
async_add_displays([LedfxrmLight(coordinator, entry)])
for k in virtuals:
async_add_devices([LedfxrmVirtualsLight(coordinator, entry, k)])
async_add_displays([LedfxrmVirtualsLight(coordinator, entry, k)])
else:
async_add_devices([LedfxrmLight(coordinator, entry)])
async_add_displays([LedfxrmLight(coordinator, entry)])


class LedfxrmLight(LedfxrmEntity, LightEntity):
Expand Down Expand Up @@ -112,7 +112,7 @@ def effect_list(self):
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return the state attributes of the entity."""
scenenames = self.coordinator.data.get("scenes").get("scenes")
devicenames = self.coordinator.data.get("devices").get("devices")
devicenames = self.coordinator.data.get("displays").get("displays")
pixels = 0
for k in devicenames:
pixels = pixels + devicenames[k]["config"].get("pixel_count")
Expand Down Expand Up @@ -203,22 +203,22 @@ def effect_list(self):
@property
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return the state attributes of the entity."""
# logging.warning("OMMMMG: %s ", self.coordinator.api.devicestates)
# logging.warning("OMMMMG: %s ", self.coordinator.api.displaystates)
if self.deviceconfig == {}:
return {"status": "error"}
return {
"IP": self.deviceconfig["ip_address"],
"Pixels": self.deviceconfig["pixel_count"],
"Refresh Rate": self.deviceconfig["refresh_rate"],
"Mode": self.coordinator.api.devicestates[self.devicename]["effect"].get(
"Mode": self.coordinator.api.displaystates[self.devicename]["effect"].get(
"name", "OFF"
),
}

@property
def is_on(self):
"""Return true if the light is on."""
return self.coordinator.api.devicestates[self.devicename]["power"]
return self.coordinator.api.displaystates[self.devicename]["power"]


class LedfxrmVirtualsLight(LedfxrmLight):
Expand Down Expand Up @@ -318,5 +318,5 @@ def device_state_attributes(self) -> Optional[Dict[str, Any]]:
@property
def is_on(self):
"""Return true if the light is on."""
# return self.coordinator.api.devicestates[self.devicename]["power"]
# return self.coordinator.api.displaystates[self.devicename]["power"]
return True
Loading

0 comments on commit 6070759

Please sign in to comment.