Skip to content

Commit 38fdde5

Browse files
committed
Fix generic not having an entity
1 parent 1ab76d2 commit 38fdde5

File tree

4 files changed

+112
-10
lines changed

4 files changed

+112
-10
lines changed

custom_components/dmx/entity/number.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def __init__(self, fixture_name: str, channel_name: str, entity_id_prefix: str |
1818
capability: Capability, universe: DmxUniverse, dmx_indexes: List[int], device: DeviceInfo, available: bool = True) -> None:
1919
super().__init__()
2020

21-
assert capability.dynamic_entities \
22-
and len(capability.dynamic_entities) == 1
21+
assert capability.dynamic_entities and len(capability.dynamic_entities) == 1
2322

2423
self._attr_name = f"{fixture_name} {channel_name}"
2524
self._attr_device_info = device

custom_components/dmx/fixture/capability.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,6 @@ def is_applicable(self, dmx_value: int):
299299
"""
300300
return self.dmx_range_start <= dmx_value <= self.dmx_range_end
301301

302-
def _define_from_range(self, start: float, end: float):
303-
self.dynamic_entities.append(
304-
DynamicMapping(
305-
start, end,
306-
self.dmx_range_start, self.dmx_range_end
307-
)
308-
)
309-
310302
def _define_from_entity(self, entities: list[Entity] | None):
311303
if not entities:
312304
return
@@ -1498,6 +1490,7 @@ class Generic(Capability):
14981490

14991491
def __init__(self, **kwargs):
15001492
super().__init__(**kwargs)
1493+
self._define_from_entity([Percent(0, '%'), Percent(100, '%')])
15011494

15021495
def icon(self) -> str:
15031496
return "mdi:dots-horizontal-circle-outline"

tests/fixtures/par-uv.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/OpenLightingProject/open-fixture-library/schema-12.5.0/schemas/fixture.json",
3+
"name": "NC-UV36",
4+
"shortName": "NC-UV36",
5+
"categories": [
6+
"Dimmer",
7+
"Strobe"
8+
],
9+
"meta": {
10+
"authors": [
11+
"Frode Slatlem Okkenhaug"
12+
],
13+
"createDate": "2025-07-10",
14+
"lastModifyDate": "2025-07-10"
15+
},
16+
"comment": "36W UV PAR-lampe",
17+
"links": {
18+
"other": [
19+
"http://localhost/"
20+
]
21+
},
22+
"physical": {
23+
"power": 36,
24+
"DMXconnector": "3-pin",
25+
"bulb": {
26+
"type": "UV LED"
27+
}
28+
},
29+
"availableChannels": {
30+
"Total dimming": {
31+
"defaultValue": "100%",
32+
"capability": {
33+
"type": "Intensity"
34+
}
35+
},
36+
"UV dimming": {
37+
"defaultValue": "0%",
38+
"capability": {
39+
"type": "ColorIntensity",
40+
"color": "UV"
41+
}
42+
},
43+
"Strobe": {
44+
"defaultValue": 0,
45+
"capability": {
46+
"type": "Generic"
47+
}
48+
}
49+
},
50+
"modes": [
51+
{
52+
"name": "A",
53+
"channels": [
54+
"Total dimming",
55+
"UV dimming",
56+
"Strobe"
57+
]
58+
},
59+
{
60+
"name": "D",
61+
"channels": [
62+
"Total dimming",
63+
"Strobe",
64+
"UV dimming"
65+
]
66+
}
67+
],
68+
"fixtureKey": "nc-uv36",
69+
"manufacturerKey": "generic",
70+
"oflURL": "https://open-fixture-library.org/generic/nc-uv36"
71+
}

tests/test_misc.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import unittest
2+
from pathlib import Path
3+
from unittest.mock import MagicMock
4+
from unittest.mock import patch
5+
6+
import homeassistant.helpers.device_registry
7+
8+
from custom_components.dmx.fixture import parser, delegator
9+
from tests.dmx_test_framework import MockDmxUniverse, MockHomeAssistant
10+
11+
device_info_mock = MagicMock()
12+
homeassistant.helpers.device_registry.DeviceInfo = device_info_mock
13+
14+
15+
class TestSelectEntity(unittest.TestCase):
16+
17+
def setUp(self):
18+
self.hass = MockHomeAssistant()
19+
self.write_ha_state_patcher = patch('homeassistant.helpers.entity.Entity.async_write_ha_state')
20+
self.mock_write_ha_state = self.write_ha_state_patcher.start()
21+
22+
self.schedule_update_patcher = patch('homeassistant.helpers.entity.Entity.async_schedule_update_ha_state')
23+
self.mock_schedule_update = self.schedule_update_patcher.start()
24+
25+
self.universe = MockDmxUniverse()
26+
27+
def tearDown(self):
28+
self.write_ha_state_patcher.stop()
29+
self.schedule_update_patcher.stop()
30+
31+
def test_uv(self):
32+
fixture_path = Path(__file__).parent / 'fixtures' / 'par-uv.json'
33+
fixture = parser.parse(str(fixture_path))
34+
channels = fixture.select_mode('A')
35+
delegator.create_entities('PAR UV', 1, channels, None, self.universe)
36+
37+
38+
if __name__ == "__main__":
39+
unittest.main()

0 commit comments

Comments
 (0)