Skip to content

Commit 73cee52

Browse files
committed
Slugify entity ID's (fixes #112)
1 parent 7d9c4b9 commit 73cee52

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

custom_components/dmx/entity/light/light_entity.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from homeassistant.core import callback
77
from homeassistant.helpers.entity import DeviceInfo
88
from homeassistant.helpers.restore_state import RestoreEntity
9+
from homeassistant.util import slugify
910

1011
from custom_components.dmx.const import DOMAIN
1112
from custom_components.dmx.entity.light import ChannelMapping, ChannelType
@@ -35,7 +36,9 @@ def __init__(
3536
self._matrix_key = matrix_key
3637
self._attr_name = f"{fixture_name} Light {matrix_key}" if matrix_key else f"{fixture_name} Light"
3738
if entity_id_prefix:
38-
base_id = entity_id_prefix if not matrix_key else f"{entity_id_prefix}_{matrix_key}"
39+
slug_prefix = slugify(entity_id_prefix)
40+
slug_matrix = slugify(matrix_key) if matrix_key else None
41+
base_id = slug_prefix if not slug_matrix else f"{slug_prefix}_{slug_matrix}"
3942
self._attr_unique_id = f"{base_id}_{fixture_fingerprint}"
4043
self.entity_id = f"light.{self._attr_unique_id}"
4144
else:

custom_components/dmx/entity/number.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from homeassistant.components.number import NumberExtraStoredData, NumberMode, RestoreNumber
44
from homeassistant.core import State, callback
55
from homeassistant.helpers.entity import DeviceInfo
6+
from homeassistant.util import slugify
67

78
from custom_components.dmx.const import DOMAIN
89
from custom_components.dmx.fixture.capability import Capability, DynamicEntity
@@ -32,7 +33,9 @@ def __init__(
3233
self._attr_device_info = device
3334

3435
if entity_id_prefix:
35-
self._attr_unique_id = f"{entity_id_prefix}_{channel_name.lower()}_{fixture_fingerprint}"
36+
slug_prefix = slugify(entity_id_prefix)
37+
slug_channel = slugify(channel_name)
38+
self._attr_unique_id = f"{slug_prefix}_{slug_channel}_{fixture_fingerprint}"
3639
self.entity_id = f"number.{self._attr_unique_id}"
3740
else:
3841
self._attr_unique_id = (

custom_components/dmx/entity/select.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from homeassistant.components.select import SelectEntity
44
from homeassistant.helpers.entity import DeviceInfo
5+
from homeassistant.util import slugify
56

67
from custom_components.dmx.const import DOMAIN
78
from custom_components.dmx.entity.icon_helper import determine_icon
@@ -32,7 +33,9 @@ def __init__(
3233
self._attr_name = f"{fixture_name} {channel_name}"
3334
self._attr_device_info = device
3435
if entity_id_prefix:
35-
self._attr_unique_id = f"{entity_id_prefix}_{channel_name.lower()}_{fixture_fingerprint}"
36+
slug_prefix = slugify(entity_id_prefix)
37+
slug_channel = slugify(channel_name)
38+
self._attr_unique_id = f"{slug_prefix}_{slug_channel}_{fixture_fingerprint}"
3639
self.entity_id = f"select.{self._attr_unique_id}"
3740
else:
3841
self._attr_unique_id = (

docs/migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ All your current fixtures are now still supported! Here's the process to get you
66

77
Our integration name changed from `artnet_led` to `dmx`. HACS doesn't allow this, so we are unable to upgrade this in-place. Therefore a manual release is needed for the beta.
88

9-
Under [the release](https://github.com/Breina/ha-artnet-led/releases/tag/v1.0.0-BETA.8) download the [source code](https://github.com/Breina/ha-artnet-led/archive/refs/tags/v1.0.0-BETA.8.zip).
9+
Under [the release](https://github.com/Breina/ha-artnet-led/releases/tag/v1.0.0-BETA.9) download the [source code](https://github.com/Breina/ha-artnet-led/archive/refs/tags/v1.0.0-BETA.9.zip).
1010

1111
In this ZIP, navigate to `custom_components/dmx` and copy this `dmx` folder into your Home Assistant's `custom_components` folder.
1212

0 commit comments

Comments
 (0)