This is a refactor to how the state of devices is set. This should reduce the amount of duplicate code. Thanks @derjoerg for the suggestions on this one.
Add new _state_refresh_output_pairings and _state_refresh_input_pairings to the Base class to store the pairings for refreshing the state of the device.
Move self._refresh_state_from_outputs() to the Base class as we have to run this on each initialization of a device.
Move the refresh_state function into the Base class and use the new _state_refresh_output_pairings to update the device state.
For each device class move the _state and _brightness (if it exists) initial setter to the __init__ of the class itself. This should ensure the devices state properties always have a value, with an initial value of None.
For the movment_detector class, it's possible it won't have brightness. Add a new test case where a movement detector doesn't have brightness but ensure the state of brightness is still set to a None value.
This is a refactor to how the state of devices is set. This should reduce the amount of duplicate code. Thanks @derjoerg for the suggestions on this one.
_state_refresh_output_pairings
and_state_refresh_input_pairings
to theBase
class to store the pairings for refreshing the state of the device.self._refresh_state_from_outputs()
to the Base class as we have to run this on each initialization of a device.refresh_state
function into the Base class and use the new_state_refresh_output_pairings
to update the device state._state
and_brightness
(if it exists) initial setter to the__init__
of the class itself. This should ensure the devices state properties always have a value, with an initial value ofNone
.