Skip to content

Commit 23481ab

Browse files
committed
0.0.6
1 parent 013d4c1 commit 23481ab

26 files changed

+1889
-628
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
UniLED Currently supports the following range of cheap BLE addressable LED controllers:
77

8-
- SP107E
9-
- SP601E
8+
- [SP107E][SP107E]
9+
- [SP601E][SP601E]
1010
- [SP611E][SP61xE]
1111
- [SP617E][SP61xE]
1212

@@ -38,8 +38,10 @@ If you want to contribute to this please read the [Contribution guidelines](CONT
3838
***
3939

4040
[uniled]: https://github.com/monty68/uniled
41+
[ha-logo]: docs/img/ha-logo-32x32.png
42+
[SP107E]: docs/sp107e.md
43+
[SP601E]: docs/sp601e.md
4144
[SP61xE]: docs/sp61Xe.md
42-
[ha-logo]: docs/ha-logo-32x32.png
4345

4446
[buymecoffee]: https://www.buymeacoffee.com/monty68
4547
[buymecoffeebadge]: https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg?style=for-the-badge

custom_components/uniled/__init__.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
from .const import DOMAIN, DEVICE_TIMEOUT
2323

2424
PLATFORMS: list[Platform] = [
25-
Platform.SENSOR,
25+
Platform.SELECT,
2626
Platform.NUMBER,
27+
Platform.SWITCH,
28+
Platform.SENSOR,
2729
Platform.LIGHT,
2830
]
2931

@@ -54,13 +56,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
5456
cancel_first_update = uniled.register_callback(lambda *_: startup_event.set())
5557
coordinator = UNILEDUpdateCoordinator(hass, uniled, entry)
5658

57-
async def _async_update():
58-
"""Update the device state."""
59-
try:
60-
await uniled.update(force=True)
61-
except BLEAK_EXCEPTIONS as ex:
62-
raise UpdateFailed(str(ex)) from ex
63-
6459
try:
6560
await coordinator.async_config_entry_first_refresh()
6661
except ConfigEntryNotReady:

custom_components/uniled/const.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
DOMAIN: Final = "uniled"
55
DEVICE_TIMEOUT = 40
66
UPDATE_SECONDS = 20
7+
REFRESH_DELAY: Final = 2.0
78

89
SIGNAL_STATE_UPDATED = "uniled_{}_state_updated"

custom_components/uniled/coordinator.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44
from datetime import timedelta
55
from typing import Final
66

7-
from homeassistant.config_entries import ConfigEntry
7+
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
88
from homeassistant.core import HomeAssistant
99
from homeassistant.helpers.debounce import Debouncer
1010
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
1111

12-
from .const import UPDATE_SECONDS
12+
from .const import UPDATE_SECONDS, REFRESH_DELAY
1313
from .lib.classes import UNILEDDevice
1414
from .lib.ble_device import BLEAK_EXCEPTIONS
1515

1616
import logging
1717

1818
_LOGGER = logging.getLogger(__name__)
1919

20-
REQUEST_REFRESH_DELAY: Final = 2.0
21-
2220

2321
class UNILEDUpdateCoordinator(DataUpdateCoordinator):
2422
"""DataUpdateCoordinator to gather data for a specific UniLED device."""
@@ -37,14 +35,15 @@ def __init__(self, hass: HomeAssistant, device: UNILEDDevice, entry: ConfigEntry
3735
# We don't want an immediate refresh since the device
3836
# takes a moment to reflect the state change
3937
request_refresh_debouncer=Debouncer(
40-
hass, _LOGGER, cooldown=REQUEST_REFRESH_DELAY, immediate=False
38+
hass, _LOGGER, cooldown=REFRESH_DELAY, immediate=False
4139
),
4240
)
4341

4442
async def _async_update_data(self) -> None:
4543
"""Fetch all device and sensor data from api."""
4644
try:
47-
await self.device.update(force=self.force_next_update)
45+
if self.entry.state != ConfigEntryState.NOT_LOADED:
46+
await self.device.update(force=self.force_next_update)
4847
except BLEAK_EXCEPTIONS as ex:
4948
raise UpdateFailed(str(ex)) from ex
5049
finally:

custom_components/uniled/entity.py

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def __init__(
5656
self._attr_unique_id = f"_{self._attr_unique_id}_{key}"
5757
self._attr_device_info = _async_device_info(self._device, coordinator.entry)
5858

59+
#@property
60+
#def force_update(self) -> bool:
61+
# return True
5962

6063
@property
6164
def id(self) -> int:

custom_components/uniled/lib/artifacts.py

+73-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class UNILEDModelType(IntEnum):
1717
STRIP = 1
1818

1919

20-
class UNILEDChipset(StrEnum):
20+
class UNILEDChipType(StrEnum):
2121
"""LED Chipset Names"""
2222

2323
SM16703 = "SM16703"
@@ -49,7 +49,47 @@ class UNILEDChipset(StrEnum):
4949
P9412 = "P9412"
5050

5151

52-
class UNILEDColorOrder(StrEnum):
52+
UNILED_CHIP_TYPES: Final = {
53+
# 3 Color - RGB
54+
0x00: UNILEDChipType.SM16703,
55+
0x01: UNILEDChipType.TM1804,
56+
0x02: UNILEDChipType.UCS1903,
57+
0x03: UNILEDChipType.WS2811,
58+
0x04: UNILEDChipType.WS2801,
59+
0x05: UNILEDChipType.SK6812,
60+
0x06: UNILEDChipType.LPD6803,
61+
0x07: UNILEDChipType.LPD8806,
62+
0x08: UNILEDChipType.APA102,
63+
0x09: UNILEDChipType.APA105,
64+
0x0A: UNILEDChipType.DMX512,
65+
0x0B: UNILEDChipType.TM1914,
66+
0x0C: UNILEDChipType.TM1913,
67+
0x0D: UNILEDChipType.P9813,
68+
0x0E: UNILEDChipType.INK1003,
69+
0x0F: UNILEDChipType.P943S,
70+
0x10: UNILEDChipType.P9411,
71+
0x11: UNILEDChipType.P9413,
72+
0x12: UNILEDChipType.TX1812,
73+
0x13: UNILEDChipType.TX1813,
74+
0x14: UNILEDChipType.GS8206,
75+
0x15: UNILEDChipType.GS8208,
76+
0x16: UNILEDChipType.SK9822,
77+
# 4 Color - RGBW
78+
0x17: UNILEDChipType.TM1814,
79+
0x18: UNILEDChipType.SK6812_RGBW,
80+
0x19: UNILEDChipType.P9414,
81+
0x1A: UNILEDChipType.P9412,
82+
}
83+
84+
UNILED_CHIP_4COLOR: Final = [
85+
0x17, # TM1814
86+
0x18, # SK6812_RGBW
87+
0x19, # P9414
88+
0x1A, # P9412
89+
]
90+
91+
92+
class UNILEDChipOrder(StrEnum):
5393
"""LED Ordering Names"""
5494

5595
RGB = "RGB"
@@ -60,7 +100,29 @@ class UNILEDColorOrder(StrEnum):
60100
BGR = "BGR"
61101

62102

63-
class UNILEDInputs(StrEnum):
103+
UNILED_CHIP_ORDERS: Final = {
104+
0x00: UNILEDChipOrder.RGB,
105+
0x01: UNILEDChipOrder.RBG,
106+
0x02: UNILEDChipOrder.GRB,
107+
0x03: UNILEDChipOrder.GBR,
108+
0x04: UNILEDChipOrder.BRG,
109+
0x05: UNILEDChipOrder.BGR,
110+
}
111+
112+
113+
class UNILEDMode(StrEnum):
114+
"""Mode Names"""
115+
116+
OFF = "Off"
117+
MANUAL = "Manual"
118+
SINGULAR = "Single FX"
119+
AUTO = "Cycle Effects"
120+
AUTO_PATTERN = "Cycle Pattern FX's"
121+
AUTO_SCENE = "Cycle Scenes"
122+
AUTO_SOUND = "Cycle Sound FX's"
123+
124+
125+
class UNILEDInput(StrEnum):
64126
"""Audio Input Names"""
65127

66128
AUXIN = "Aux In"
@@ -77,6 +139,13 @@ class UNILEDEffectType(StrEnum):
77139
SOUND = "Sound"
78140

79141

142+
class UNILEDEffectDirection(StrEnum):
143+
"""Effect Direction Names"""
144+
145+
BACKWARDS = "Backwards"
146+
FORWARDS = "Forwards"
147+
148+
80149
class UNILEDEffects(StrEnum):
81150
"""Effect/Pattern Names"""
82151

@@ -167,6 +236,7 @@ class UNILEDEffects(StrEnum):
167236
WAVE_PURPLE_WHITE = "Purple/White Wave"
168237

169238
STARS = "Stars"
239+
STARS_TWINKLE = "Twinkle Stars"
170240
STARS_RED = "Red Stars"
171241
STARS_GREEN = "Green Stars"
172242
STARS_BLUE = "Blue Stars"

0 commit comments

Comments
 (0)