core/homeassistant/components/rflink/light.py

279 lines
9.6 KiB
Python
Raw Normal View History

"""Support for Rflink lights."""
from __future__ import annotations
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
import logging
import re
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
import voluptuous as vol
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
from homeassistant.components.light import (
2019-07-31 19:25:30 +00:00
ATTR_BRIGHTNESS,
PLATFORM_SCHEMA,
SUPPORT_BRIGHTNESS,
2020-04-26 16:49:41 +00:00
LightEntity,
2019-07-31 19:25:30 +00:00
)
2021-02-12 22:32:56 +00:00
from homeassistant.const import CONF_DEVICES, CONF_NAME, CONF_TYPE
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import (
2019-07-31 19:25:30 +00:00
CONF_ALIASES,
CONF_AUTOMATIC_ADD,
CONF_DEVICE_DEFAULTS,
CONF_FIRE_EVENT,
CONF_GROUP,
CONF_GROUP_ALIASES,
CONF_NOGROUP_ALIASES,
CONF_SIGNAL_REPETITIONS,
DATA_DEVICE_REGISTER,
DEVICE_DEFAULTS_SCHEMA,
EVENT_KEY_COMMAND,
EVENT_KEY_ID,
SwitchableRflinkDevice,
)
from .utils import brightness_to_rflink, rflink_to_brightness
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
_LOGGER = logging.getLogger(__name__)
PARALLEL_UPDATES = 0
2019-07-31 19:25:30 +00:00
TYPE_DIMMABLE = "dimmable"
TYPE_SWITCHABLE = "switchable"
TYPE_HYBRID = "hybrid"
TYPE_TOGGLE = "toggle"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(
CONF_DEVICE_DEFAULTS, default=DEVICE_DEFAULTS_SCHEMA({})
): DEVICE_DEFAULTS_SCHEMA,
vol.Optional(CONF_AUTOMATIC_ADD, default=True): cv.boolean,
vol.Optional(CONF_DEVICES, default={}): {
cv.string: vol.Schema(
{
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_TYPE): vol.Any(
TYPE_DIMMABLE, TYPE_SWITCHABLE, TYPE_HYBRID, TYPE_TOGGLE
),
vol.Optional(CONF_ALIASES, default=[]): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(CONF_GROUP_ALIASES, default=[]): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(CONF_NOGROUP_ALIASES, default=[]): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(CONF_FIRE_EVENT): cv.boolean,
vol.Optional(CONF_SIGNAL_REPETITIONS): vol.Coerce(int),
vol.Optional(CONF_GROUP, default=True): cv.boolean,
}
)
},
},
2019-07-31 19:25:30 +00:00
extra=vol.ALLOW_EXTRA,
)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
def entity_type_for_device_id(device_id):
"""Return entity class for protocol of a given device_id.
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
Async friendly.
"""
entity_type_mapping = {
# KlikAanKlikUit support both dimmers and on/off switches on the same
# protocol
2019-07-31 19:25:30 +00:00
"newkaku": TYPE_HYBRID
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
}
2019-07-31 19:25:30 +00:00
protocol = device_id.split("_")[0]
return entity_type_mapping.get(protocol)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
def entity_class_for_type(entity_type):
"""Translate entity type to entity class.
Async friendly.
"""
entity_device_mapping = {
# sends only 'dim' commands not compatible with on/off switches
TYPE_DIMMABLE: DimmableRflinkLight,
# sends only 'on/off' commands not advices with dimmers and signal
# repetition
TYPE_SWITCHABLE: RflinkLight,
# sends 'dim' and 'on' command to support both dimmers and on/off
# switches. Not compatible with signal repetition.
TYPE_HYBRID: HybridRflinkLight,
# sends only 'on' commands for switches which turn on and off
# using the same 'on' command for both.
TYPE_TOGGLE: ToggleRflinkLight,
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
}
return entity_device_mapping.get(entity_type, RflinkLight)
def devices_from_config(domain_config):
"""Parse configuration and add Rflink light devices."""
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
devices = []
for device_id, config in domain_config[CONF_DEVICES].items():
# Determine which kind of entity to create
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
if CONF_TYPE in config:
# Remove type from config to not pass it as and argument to entity
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
# instantiation
entity_type = config.pop(CONF_TYPE)
else:
entity_type = entity_type_for_device_id(device_id)
entity_class = entity_class_for_type(entity_type)
device_config = dict(domain_config[CONF_DEVICE_DEFAULTS], **config)
is_hybrid = entity_class is HybridRflinkLight
# Make user aware this can cause problems
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
repetitions_enabled = device_config[CONF_SIGNAL_REPETITIONS] != 1
if is_hybrid and repetitions_enabled:
_LOGGER.warning(
"Hybrid type for %s not compatible with signal "
"repetitions. Please set 'dimmable' or 'switchable' "
2019-07-31 19:25:30 +00:00
"type explicitly in configuration",
device_id,
)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
device = entity_class(device_id, **device_config)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
devices.append(device)
return devices
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Rflink light platform."""
async_add_entities(devices_from_config(config))
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
async def add_new_device(event):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""Check if device is known, otherwise add to list of known devices."""
device_id = event[EVENT_KEY_ID]
entity_type = entity_type_for_device_id(event[EVENT_KEY_ID])
entity_class = entity_class_for_type(entity_type)
device_config = config[CONF_DEVICE_DEFAULTS]
device = entity_class(device_id, initial_event=event, **device_config)
async_add_entities([device])
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
if config[CONF_AUTOMATIC_ADD]:
hass.data[DATA_DEVICE_REGISTER][EVENT_KEY_COMMAND] = add_new_device
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
2020-04-26 16:49:41 +00:00
class RflinkLight(SwitchableRflinkDevice, LightEntity):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""Representation of a Rflink light."""
2020-04-26 16:49:41 +00:00
class DimmableRflinkLight(SwitchableRflinkDevice, LightEntity):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""Rflink light device that support dimming."""
_brightness = 255
async def async_added_to_hass(self):
"""Restore RFLink light brightness attribute."""
await super().async_added_to_hass()
old_state = await self.async_get_last_state()
2019-07-31 19:25:30 +00:00
if (
old_state is not None
and old_state.attributes.get(ATTR_BRIGHTNESS) is not None
):
# restore also brightness in dimmables devices
self._brightness = int(old_state.attributes[ATTR_BRIGHTNESS])
async def async_turn_on(self, **kwargs):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""Turn the device on."""
if ATTR_BRIGHTNESS in kwargs:
# rflink only support 16 brightness levels
self._brightness = rflink_to_brightness(
brightness_to_rflink(kwargs[ATTR_BRIGHTNESS])
)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
# Turn on light at the requested dim level
2019-07-31 19:25:30 +00:00
await self._async_handle_command("dim", self._brightness)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
def _handle_event(self, event):
"""Adjust state if Rflink picks up a remote command for this device."""
self.cancel_queued_send_commands()
command = event["command"]
if command in ["on", "allon"]:
self._state = True
elif command in ["off", "alloff"]:
self._state = False
# dimmable device accept 'set_level=(0-15)' commands
elif re.search("^set_level=(0?[0-9]|1[0-5])$", command, re.IGNORECASE):
self._brightness = rflink_to_brightness(int(command.split("=")[1]))
self._state = True
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
return self._brightness
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_BRIGHTNESS
class HybridRflinkLight(DimmableRflinkLight, LightEntity):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""Rflink light device that sends out both dim and on/off commands.
Used for protocols which support lights that are not exclusively on/off
style. For example KlikAanKlikUit supports both on/off and dimmable light
switches using the same protocol. This type allows unconfigured
KlikAanKlikUit devices to support dimming without breaking support for
on/off switches.
This type is not compatible with signal repetitions as the 'dim' and 'on'
command are send sequential and multiple 'on' commands to a dimmable
device can cause the dimmer to switch into a pulsating brightness mode.
Which results in a nice house disco :)
"""
async def async_turn_on(self, **kwargs):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""Turn the device on and set dim level."""
await super().async_turn_on(**kwargs)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
# if the receiving device does not support dimlevel this
# will ensure it is turned on when full brightness is set
if self.brightness == 255:
2019-07-31 19:25:30 +00:00
await self._async_handle_command("turn_on")
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
2020-04-26 16:49:41 +00:00
class ToggleRflinkLight(SwitchableRflinkDevice, LightEntity):
"""Rflink light device which sends out only 'on' commands.
Some switches like for example Livolo light switches use the
same 'on' command to switch on and switch off the lights.
If the light is on and 'on' gets sent, the light will turn off
and if the light is off and 'on' gets sent, the light will turn on.
"""
def _handle_event(self, event):
"""Adjust state if Rflink picks up a remote command for this device."""
self.cancel_queued_send_commands()
2021-10-30 14:33:42 +00:00
if event["command"] == "on":
# if the state is unknown or false, it gets set as true
# if the state is true, it gets set as false
self._state = self._state in [None, False]
async def async_turn_on(self, **kwargs):
"""Turn the device on."""
2019-07-31 19:25:30 +00:00
await self._async_handle_command("toggle")
async def async_turn_off(self, **kwargs):
"""Turn the device off."""
2019-07-31 19:25:30 +00:00
await self._async_handle_command("toggle")