mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Move shared rflink constants to separate module (#126173)
This commit is contained in:
parent
47657af173
commit
df434fc5e2
@ -32,38 +32,32 @@ from homeassistant.helpers.event import async_call_later
|
|||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .utils import brightness_to_rflink
|
from .const import (
|
||||||
|
DATA_DEVICE_REGISTER,
|
||||||
|
DATA_ENTITY_LOOKUP,
|
||||||
|
DEFAULT_SIGNAL_REPETITIONS,
|
||||||
|
EVENT_KEY_COMMAND,
|
||||||
|
EVENT_KEY_ID,
|
||||||
|
EVENT_KEY_SENSOR,
|
||||||
|
SIGNAL_AVAILABILITY,
|
||||||
|
SIGNAL_HANDLE_EVENT,
|
||||||
|
TMP_ENTITY,
|
||||||
|
)
|
||||||
|
from .utils import brightness_to_rflink, identify_event_type
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_EVENT = "event"
|
|
||||||
|
|
||||||
CONF_ALIASES = "aliases"
|
|
||||||
CONF_GROUP_ALIASES = "group_aliases"
|
|
||||||
CONF_GROUP = "group"
|
|
||||||
CONF_NOGROUP_ALIASES = "nogroup_aliases"
|
|
||||||
CONF_DEVICE_DEFAULTS = "device_defaults"
|
|
||||||
CONF_AUTOMATIC_ADD = "automatic_add"
|
|
||||||
CONF_FIRE_EVENT = "fire_event"
|
|
||||||
CONF_IGNORE_DEVICES = "ignore_devices"
|
CONF_IGNORE_DEVICES = "ignore_devices"
|
||||||
CONF_RECONNECT_INTERVAL = "reconnect_interval"
|
CONF_RECONNECT_INTERVAL = "reconnect_interval"
|
||||||
CONF_SIGNAL_REPETITIONS = "signal_repetitions"
|
|
||||||
CONF_WAIT_FOR_ACK = "wait_for_ack"
|
CONF_WAIT_FOR_ACK = "wait_for_ack"
|
||||||
CONF_KEEPALIVE_IDLE = "tcp_keepalive_idle_timer"
|
CONF_KEEPALIVE_IDLE = "tcp_keepalive_idle_timer"
|
||||||
|
|
||||||
DATA_DEVICE_REGISTER = "rflink_device_register"
|
|
||||||
DATA_ENTITY_LOOKUP = "rflink_entity_lookup"
|
|
||||||
DATA_ENTITY_GROUP_LOOKUP = "rflink_entity_group_only_lookup"
|
DATA_ENTITY_GROUP_LOOKUP = "rflink_entity_group_only_lookup"
|
||||||
DEFAULT_RECONNECT_INTERVAL = 10
|
DEFAULT_RECONNECT_INTERVAL = 10
|
||||||
DEFAULT_SIGNAL_REPETITIONS = 1
|
|
||||||
DEFAULT_TCP_KEEPALIVE_IDLE_TIMER = 3600
|
DEFAULT_TCP_KEEPALIVE_IDLE_TIMER = 3600
|
||||||
CONNECTION_TIMEOUT = 10
|
CONNECTION_TIMEOUT = 10
|
||||||
|
|
||||||
EVENT_BUTTON_PRESSED = "button_pressed"
|
EVENT_BUTTON_PRESSED = "button_pressed"
|
||||||
EVENT_KEY_COMMAND = "command"
|
|
||||||
EVENT_KEY_ID = "id"
|
|
||||||
EVENT_KEY_SENSOR = "sensor"
|
|
||||||
EVENT_KEY_UNIT = "unit"
|
|
||||||
|
|
||||||
RFLINK_GROUP_COMMANDS = ["allon", "alloff"]
|
RFLINK_GROUP_COMMANDS = ["allon", "alloff"]
|
||||||
|
|
||||||
@ -71,20 +65,8 @@ DOMAIN = "rflink"
|
|||||||
|
|
||||||
SERVICE_SEND_COMMAND = "send_command"
|
SERVICE_SEND_COMMAND = "send_command"
|
||||||
|
|
||||||
SIGNAL_AVAILABILITY = "rflink_device_available"
|
|
||||||
SIGNAL_HANDLE_EVENT = "rflink_handle_event_{}"
|
|
||||||
SIGNAL_EVENT = "rflink_event"
|
SIGNAL_EVENT = "rflink_event"
|
||||||
|
|
||||||
TMP_ENTITY = "tmp.{}"
|
|
||||||
|
|
||||||
DEVICE_DEFAULTS_SCHEMA = vol.Schema(
|
|
||||||
{
|
|
||||||
vol.Optional(CONF_FIRE_EVENT, default=False): cv.boolean,
|
|
||||||
vol.Optional(
|
|
||||||
CONF_SIGNAL_REPETITIONS, default=DEFAULT_SIGNAL_REPETITIONS
|
|
||||||
): vol.Coerce(int),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
@ -113,18 +95,6 @@ SEND_COMMAND_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def identify_event_type(event):
|
|
||||||
"""Look at event to determine type of device.
|
|
||||||
|
|
||||||
Async friendly.
|
|
||||||
"""
|
|
||||||
if EVENT_KEY_COMMAND in event:
|
|
||||||
return EVENT_KEY_COMMAND
|
|
||||||
if EVENT_KEY_SENSOR in event:
|
|
||||||
return EVENT_KEY_SENSOR
|
|
||||||
return "unknown"
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Rflink component."""
|
"""Set up the Rflink component."""
|
||||||
# Allow entities to register themselves by device_id to be looked up when
|
# Allow entities to register themselves by device_id to be looked up when
|
||||||
|
@ -26,7 +26,8 @@ import homeassistant.helpers.event as evt
|
|||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import CONF_ALIASES, RflinkDevice
|
from . import RflinkDevice
|
||||||
|
from .const import CONF_ALIASES
|
||||||
|
|
||||||
CONF_OFF_DELAY = "off_delay"
|
CONF_OFF_DELAY = "off_delay"
|
||||||
DEFAULT_FORCE_UPDATE = False
|
DEFAULT_FORCE_UPDATE = False
|
||||||
|
39
homeassistant/components/rflink/const.py
Normal file
39
homeassistant/components/rflink/const.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
"""Support for Rflink devices."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
CONF_ALIASES = "aliases"
|
||||||
|
CONF_GROUP_ALIASES = "group_aliases"
|
||||||
|
CONF_GROUP = "group"
|
||||||
|
CONF_NOGROUP_ALIASES = "nogroup_aliases"
|
||||||
|
CONF_DEVICE_DEFAULTS = "device_defaults"
|
||||||
|
CONF_AUTOMATIC_ADD = "automatic_add"
|
||||||
|
CONF_FIRE_EVENT = "fire_event"
|
||||||
|
CONF_SIGNAL_REPETITIONS = "signal_repetitions"
|
||||||
|
|
||||||
|
DATA_DEVICE_REGISTER = "rflink_device_register"
|
||||||
|
DATA_ENTITY_LOOKUP = "rflink_entity_lookup"
|
||||||
|
DEFAULT_SIGNAL_REPETITIONS = 1
|
||||||
|
|
||||||
|
EVENT_KEY_COMMAND = "command"
|
||||||
|
EVENT_KEY_ID = "id"
|
||||||
|
EVENT_KEY_SENSOR = "sensor"
|
||||||
|
EVENT_KEY_UNIT = "unit"
|
||||||
|
|
||||||
|
SIGNAL_AVAILABILITY = "rflink_device_available"
|
||||||
|
SIGNAL_HANDLE_EVENT = "rflink_handle_event_{}"
|
||||||
|
|
||||||
|
TMP_ENTITY = "tmp.{}"
|
||||||
|
|
||||||
|
DEVICE_DEFAULTS_SCHEMA = vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Optional(CONF_FIRE_EVENT, default=False): cv.boolean,
|
||||||
|
vol.Optional(
|
||||||
|
CONF_SIGNAL_REPETITIONS, default=DEFAULT_SIGNAL_REPETITIONS
|
||||||
|
): vol.Coerce(int),
|
||||||
|
}
|
||||||
|
)
|
@ -18,7 +18,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import (
|
from . import RflinkCommand
|
||||||
|
from .const import (
|
||||||
CONF_ALIASES,
|
CONF_ALIASES,
|
||||||
CONF_DEVICE_DEFAULTS,
|
CONF_DEVICE_DEFAULTS,
|
||||||
CONF_FIRE_EVENT,
|
CONF_FIRE_EVENT,
|
||||||
@ -27,7 +28,6 @@ from . import (
|
|||||||
CONF_NOGROUP_ALIASES,
|
CONF_NOGROUP_ALIASES,
|
||||||
CONF_SIGNAL_REPETITIONS,
|
CONF_SIGNAL_REPETITIONS,
|
||||||
DEVICE_DEFAULTS_SCHEMA,
|
DEVICE_DEFAULTS_SCHEMA,
|
||||||
RflinkCommand,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -20,7 +20,8 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import (
|
from . import SwitchableRflinkDevice
|
||||||
|
from .const import (
|
||||||
CONF_ALIASES,
|
CONF_ALIASES,
|
||||||
CONF_AUTOMATIC_ADD,
|
CONF_AUTOMATIC_ADD,
|
||||||
CONF_DEVICE_DEFAULTS,
|
CONF_DEVICE_DEFAULTS,
|
||||||
@ -33,7 +34,6 @@ from . import (
|
|||||||
DEVICE_DEFAULTS_SCHEMA,
|
DEVICE_DEFAULTS_SCHEMA,
|
||||||
EVENT_KEY_COMMAND,
|
EVENT_KEY_COMMAND,
|
||||||
EVENT_KEY_ID,
|
EVENT_KEY_ID,
|
||||||
SwitchableRflinkDevice,
|
|
||||||
)
|
)
|
||||||
from .utils import brightness_to_rflink, rflink_to_brightness
|
from .utils import brightness_to_rflink, rflink_to_brightness
|
||||||
|
|
||||||
|
@ -40,7 +40,8 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import (
|
from . import RflinkDevice
|
||||||
|
from .const import (
|
||||||
CONF_ALIASES,
|
CONF_ALIASES,
|
||||||
CONF_AUTOMATIC_ADD,
|
CONF_AUTOMATIC_ADD,
|
||||||
DATA_DEVICE_REGISTER,
|
DATA_DEVICE_REGISTER,
|
||||||
@ -51,7 +52,6 @@ from . import (
|
|||||||
SIGNAL_AVAILABILITY,
|
SIGNAL_AVAILABILITY,
|
||||||
SIGNAL_HANDLE_EVENT,
|
SIGNAL_HANDLE_EVENT,
|
||||||
TMP_ENTITY,
|
TMP_ENTITY,
|
||||||
RflinkDevice,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
SENSOR_TYPES = (
|
SENSOR_TYPES = (
|
||||||
|
@ -14,7 +14,8 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import (
|
from . import SwitchableRflinkDevice
|
||||||
|
from .const import (
|
||||||
CONF_ALIASES,
|
CONF_ALIASES,
|
||||||
CONF_DEVICE_DEFAULTS,
|
CONF_DEVICE_DEFAULTS,
|
||||||
CONF_FIRE_EVENT,
|
CONF_FIRE_EVENT,
|
||||||
@ -23,7 +24,6 @@ from . import (
|
|||||||
CONF_NOGROUP_ALIASES,
|
CONF_NOGROUP_ALIASES,
|
||||||
CONF_SIGNAL_REPETITIONS,
|
CONF_SIGNAL_REPETITIONS,
|
||||||
DEVICE_DEFAULTS_SCHEMA,
|
DEVICE_DEFAULTS_SCHEMA,
|
||||||
SwitchableRflinkDevice,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""RFLink integration utils."""
|
"""RFLink integration utils."""
|
||||||
|
|
||||||
|
from .const import EVENT_KEY_COMMAND, EVENT_KEY_SENSOR
|
||||||
|
|
||||||
|
|
||||||
def brightness_to_rflink(brightness: int) -> int:
|
def brightness_to_rflink(brightness: int) -> int:
|
||||||
"""Convert 0-255 brightness to RFLink dim level (0-15)."""
|
"""Convert 0-255 brightness to RFLink dim level (0-15)."""
|
||||||
@ -9,3 +11,15 @@ def brightness_to_rflink(brightness: int) -> int:
|
|||||||
def rflink_to_brightness(dim_level: int) -> int:
|
def rflink_to_brightness(dim_level: int) -> int:
|
||||||
"""Convert RFLink dim level (0-15) to 0-255 brightness."""
|
"""Convert RFLink dim level (0-15) to 0-255 brightness."""
|
||||||
return int(dim_level * 17)
|
return int(dim_level * 17)
|
||||||
|
|
||||||
|
|
||||||
|
def identify_event_type(event):
|
||||||
|
"""Look at event to determine type of device.
|
||||||
|
|
||||||
|
Async friendly.
|
||||||
|
"""
|
||||||
|
if EVENT_KEY_COMMAND in event:
|
||||||
|
return EVENT_KEY_COMMAND
|
||||||
|
if EVENT_KEY_SENSOR in event:
|
||||||
|
return EVENT_KEY_SENSOR
|
||||||
|
return "unknown"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user