Skip to content

Commit

Permalink
Merge pull request #49 from markvader/unique_id_testing
Browse files Browse the repository at this point in the history
Addition of Unique id functionality & documentation
  • Loading branch information
markvader authored Sep 26, 2022
2 parents 3e3cd78 + f33f0f2 commit 1af15f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,20 @@ switch:
| `pulselength` | no | | integer | Pulselength. |
| `signal_repetitions` | no | `10` | integer | Number of times to repeat transmission. |
| `length` | no | `24` | integer | Code Length |



## Additional Customisation

Thanks to the [work](https://github.com/markvader/ha-rpi_rf/pull/48) of [@oskargert](https://www.github.com/oskargert) this integration's switch entities now utilises unique_id's which allow us to customise a lot more features within home assistant such as Icons, Show as, Area and the ability to quickly rename the Entity Name & Entity ID. Just click on the entity name, then go to the settings tab, and make it your own.

![additional customisation rpi-rf](https://user-images.githubusercontent.com/217953/192374175-fe598f1b-e1c0-45ab-a167-d6c199902100.png)


**An important note on this.**
- The unique_id for each entity is generated from the code_on & code_off values.
- Should you change these in the future and/or add additional code(s) to a code sequence, the unique_id will be regenerated and Home Assistant will recognise a new entity.
- It is safe to remove the old entity (It will show as "restored" in the list of entities).
- The old entity and its customisation (icon, area etc) will be lost and you will need to reenter these customisations for the new entity.

- Additionally, you will be unable to have two entities with identical code_on & code_off values (not sure thats ever likely to happen as if you had more than one device in a home with the same RF codes as it would be impossible to control a single device.)
2 changes: 1 addition & 1 deletion custom_components/rpi_rf/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"requirements": ["RPi.GPIO==0.7.1", "rpi-rf==0.9.7"],
"codeowners": ["@markvader"],
"iot_class": "assumed_state",
"version": "2022.7.0"
"version": "2022.9.0"
}
9 changes: 7 additions & 2 deletions custom_components/rpi_rf/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
from homeassistant.const import (
CONF_NAME,
CONF_UNIQUE_ID,
CONF_PROTOCOL,
CONF_SWITCHES,
EVENT_HOMEASSISTANT_STOP,
Expand Down Expand Up @@ -40,6 +41,7 @@
vol.Optional(CONF_SIGNAL_REPETITIONS, default=DEFAULT_SIGNAL_REPETITIONS): cv.positive_int,
vol.Optional(CONF_PROTOCOL, default=DEFAULT_PROTOCOL): cv.positive_int,
vol.Optional(CONF_LENGTH, default=DEFAULT_LENGTH): cv.positive_int,
vol.Optional(CONF_UNIQUE_ID): cv.string,
}
)

Expand All @@ -58,7 +60,7 @@ def setup_platform(
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Find and return switches controlled by a generic RF device via GPIO."""

rpi_rf = importlib.import_module("rpi_rf")

gpio = config[CONF_GPIO]
Expand All @@ -71,6 +73,7 @@ def setup_platform(
devices.append(
RPiRFSwitch(
properties.get(CONF_NAME, dev_name),
properties.get(CONF_UNIQUE_ID),
rfdevice,
rfdevice_lock,
properties.get(CONF_PROTOCOL),
Expand All @@ -95,6 +98,7 @@ class RPiRFSwitch(SwitchEntity):
def __init__(
self,
name,
unique_id,
rfdevice,
lock,
protocol,
Expand All @@ -106,6 +110,7 @@ def __init__(
):
"""Initialize the switch."""
self._name = name
self._attr_unique_id = unique_id if unique_id else "{}_{}".format(code_on, code_off)
self._state = False
self._rfdevice = rfdevice
self._lock = lock
Expand All @@ -115,7 +120,7 @@ def __init__(
self._code_on = code_on
self._code_off = code_off
self._rfdevice.tx_repeat = signal_repetitions

@property
def should_poll(self):
"""No polling needed."""
Expand Down

0 comments on commit 1af15f7

Please sign in to comment.