diff --git a/custom_components/ledfxrm/__init__.py b/custom_components/ledfxrm/__init__.py index 9ead73c..ed07489 100644 --- a/custom_components/ledfxrm/__init__.py +++ b/custom_components/ledfxrm/__init__.py @@ -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) @@ -78,7 +78,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): thestart, thestop, thescan, - thesubdevices, + thesubdisplays, theblade_light, thestart_method, thestart_body, @@ -113,7 +113,7 @@ def __init__( theport, thestart, thestop, - thesubdevices, + thesubdisplays, theblade_light, thestart_method, thestart_body, @@ -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 @@ -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"] = {} @@ -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: @@ -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() @@ -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): @@ -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" ) @@ -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" ) @@ -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 = { @@ -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): @@ -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")): @@ -521,7 +521,7 @@ def __init__( theblade_light, thestop, thescan, - thesubdevices, + thesubdisplays, thestart_method, thestart_body, thestop_method, @@ -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 @@ -547,7 +547,7 @@ def __init__( theport, thestart, thestop, - thesubdevices, + thesubdisplays, theblade_light, thestart_method, thestart_body, @@ -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 @@ -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": {}}, } diff --git a/custom_components/ledfxrm/binary_sensor.py b/custom_components/ledfxrm/binary_sensor.py index 523d84c..6c6e9ed 100644 --- a/custom_components/ledfxrm/binary_sensor.py +++ b/custom_components/ledfxrm/binary_sensor.py @@ -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 ): diff --git a/custom_components/ledfxrm/const.py b/custom_components/ledfxrm/const.py index f7a8a5e..cc30cc0 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.2.6" +VERSION = "0.2.9" MANUFACTURER = "YeonV" ISSUE_URL = "https://github.com/YeonV/ledfxrm/issues" @@ -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" diff --git a/custom_components/ledfxrm/light.py b/custom_components/ledfxrm/light.py index 72e143c..a2b7694 100644 --- a/custom_components/ledfxrm/light.py +++ b/custom_components/ledfxrm/light.py @@ -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): @@ -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") @@ -203,14 +203,14 @@ 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" ), } @@ -218,7 +218,7 @@ 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"] class LedfxrmVirtualsLight(LedfxrmLight): @@ -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 diff --git a/custom_components/ledfxrm/manifest.json b/custom_components/ledfxrm/manifest.json index 4a7b0aa..3839254 100644 --- a/custom_components/ledfxrm/manifest.json +++ b/custom_components/ledfxrm/manifest.json @@ -7,5 +7,5 @@ "codeowners": ["@YeonV"], "requirements": [], "config_flow": true, - "version": "0.2.8" + "version": "0.2.9" } diff --git a/custom_components/ledfxrm/sensor.py b/custom_components/ledfxrm/sensor.py index 02d50a1..0c236bb 100644 --- a/custom_components/ledfxrm/sensor.py +++ b/custom_components/ledfxrm/sensor.py @@ -4,10 +4,10 @@ from typing import Any, Callable, Dict, List, Optional import logging -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] - async_add_devices([ + async_add_displays([ LedfxrmSensor(coordinator, entry), LedfxrmDeviceSensor(coordinator, entry), LedfxrmPixelSensor(coordinator, entry), @@ -28,7 +28,7 @@ def name(self): @property def state(self): """Return the state of the sensor.""" - 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') @@ -44,7 +44,7 @@ class LedfxrmDeviceSensor(LedfxrmEntity): @property def unique_id(self): """Return a unique ID to use for this entity.""" - return self.config_entry.entry_id + '_devices' + return self.config_entry.entry_id + '_displays' @property def name(self): @@ -54,7 +54,7 @@ def name(self): @property def state(self): """Return the state of the sensor.""" - devicenames = self.coordinator.data.get('devices').get('devices') + devicenames = self.coordinator.data.get('displays').get('displays') return len(devicenames) @property diff --git a/custom_components/ledfxrm/switch.py b/custom_components/ledfxrm/switch.py index 690a41e..760480b 100644 --- a/custom_components/ledfxrm/switch.py +++ b/custom_components/ledfxrm/switch.py @@ -12,10 +12,10 @@ import logging -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] - async_add_devices([LedfxrmBinarySwitch(coordinator, entry)]) + async_add_displays([LedfxrmBinarySwitch(coordinator, entry)]) class LedfxrmBinarySwitch(LedfxrmEntity, SwitchEntity): diff --git a/custom_components/ledfxrm/translations/en.json b/custom_components/ledfxrm/translations/en.json index c4ce1aa..1f9b903 100644 --- a/custom_components/ledfxrm/translations/en.json +++ b/custom_components/ledfxrm/translations/en.json @@ -1,63 +1,63 @@ { - "config": { - "step": { - "user": { - "title": "LedFx Remote - Setup", - "description": "Welcome\nPlease make sure you meet the requirements:\n- LedFx Server >0.7 up and running\n- At lease one scene defined in LedFx\n- Change host in ledfx-confi-yaml from 127.0.0.1 to your IP\n (maybe 0.0.0.0 also work)\n alternativly you can start it with `ledfx --host 0.0.0.0`\n\nIf you need help with the configuration have a look here: https://github.com/YeonV/ledfxrm", - "data": { - "thehost": "192.168.1.56", - "theport": "8888", - "host": "Host", - "port": "Port", - "start": "Start-Endpoint", - "start_method": "Method for Start-Endpoint", - "start_body": "JSON-Body for Start-Endpoint", - "stop": "Stop-Endpoint", - "stop_method": "Method for Stop-Endpoint", - "stop_body": "JSON-Body for End-Endpoint", - "scan_interval": "Scan interval in seconds", - "advanced": "Add Start/Stop-Server custom-endpoint", - "show_subdevices": "Create Entities for SubDevices", - "show_blade_light": "Add Virtual-Lights (requires LedFx >0.9.2)" - } - }, - "user_2": { - "title": "LedFx Remote - Advanced Setup", - "description": "https://github.com/YeonV/ledfxrm", - "data": { - "thehost": "192.168.1.56", - "theport": "8888", - "host": "Host", - "port": "Port", - "start": "Start-Endpoint", - "start_method": "Method for Start-Endpoint", - "start_body": "JSON-Body for Start-Endpoint", - "stop": "Stop-Endpoint", - "stop_method": "Method for Stop-Endpoint", - "stop_body": "JSON-Body for End-Endpoint", - "scan_interval": "Scan interval in seconds", - "advanced": "Advanced Settings", - "show_subdevices": "Create Entities for SubDevices?" - } - } - }, - "error": { - "auth": "Cannot connect to LedFx." - }, - "abort": { - "single_instance_allowed": "Only a single configuration of Ledfxrm is allowed." + "config": { + "step": { + "user": { + "title": "LedFx Remote - Setup", + "description": "Welcome\nPlease make sure you meet the requirements:\n- LedFx Server >0.7 up and running\n- At lease one scene defined in LedFx\n- Change host in ledfx-confi-yaml from 127.0.0.1 to your IP\n (maybe 0.0.0.0 also work)\n alternativly you can start it with `ledfx --host 0.0.0.0`\n\nIf you need help with the configuration have a look here: https://github.com/YeonV/ledfxrm", + "data": { + "thehost": "192.168.1.56", + "theport": "8888", + "host": "Host", + "port": "Port", + "start": "Start-Endpoint", + "start_method": "Method for Start-Endpoint", + "start_body": "JSON-Body for Start-Endpoint", + "stop": "Stop-Endpoint", + "stop_method": "Method for Stop-Endpoint", + "stop_body": "JSON-Body for End-Endpoint", + "scan_interval": "Scan interval in seconds", + "advanced": "Add Start/Stop-Server custom-endpoint", + "show_subdisplays": "Create Entities for SubDevices", + "show_blade_light": "Add Virtual-Lights (requires LedFx >0.9.2)" } + }, + "user_2": { + "title": "LedFx Remote - Advanced Setup", + "description": "https://github.com/YeonV/ledfxrm", + "data": { + "thehost": "192.168.1.56", + "theport": "8888", + "host": "Host", + "port": "Port", + "start": "Start-Endpoint", + "start_method": "Method for Start-Endpoint", + "start_body": "JSON-Body for Start-Endpoint", + "stop": "Stop-Endpoint", + "stop_method": "Method for Stop-Endpoint", + "stop_body": "JSON-Body for End-Endpoint", + "scan_interval": "Scan interval in seconds", + "advanced": "Advanced Settings", + "show_subdisplays": "Create Entities for SubDevices?" + } + } + }, + "error": { + "auth": "Cannot connect to LedFx." }, - "options": { - "step": { - "user": { - "data": { - "binary_sensor": "Binary sensor enabled", - "light": "Light enabled", - "sensor": "Sensor enabled", - "switch": "Switch enabled" - } - } + "abort": { + "single_instance_allowed": "Only a single configuration of Ledfxrm is allowed." + } + }, + "options": { + "step": { + "user": { + "data": { + "binary_sensor": "Binary sensor enabled", + "light": "Light enabled", + "sensor": "Sensor enabled", + "switch": "Switch enabled" } + } } -} \ No newline at end of file + } +}