mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Use HassKey in ads (#125735)
This commit is contained in:
parent
79f3e30fb6
commit
059fbe7958
@ -15,11 +15,11 @@ from homeassistant.core import HomeAssistant, ServiceCall
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
|
from .const import CONF_ADS_VAR, DATA_ADS, DOMAIN
|
||||||
from .hub import AdsHub
|
from .hub import AdsHub
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DATA_ADS = "data_ads"
|
|
||||||
|
|
||||||
# Supported Types
|
# Supported Types
|
||||||
ADSTYPE_BOOL = "bool"
|
ADSTYPE_BOOL = "bool"
|
||||||
@ -63,15 +63,7 @@ ADS_TYPEMAP = {
|
|||||||
CONF_ADS_FACTOR = "factor"
|
CONF_ADS_FACTOR = "factor"
|
||||||
CONF_ADS_TYPE = "adstype"
|
CONF_ADS_TYPE = "adstype"
|
||||||
CONF_ADS_VALUE = "value"
|
CONF_ADS_VALUE = "value"
|
||||||
CONF_ADS_VAR = "adsvar"
|
|
||||||
CONF_ADS_VAR_BRIGHTNESS = "adsvar_brightness"
|
|
||||||
CONF_ADS_VAR_POSITION = "adsvar_position"
|
|
||||||
|
|
||||||
STATE_KEY_STATE = "state"
|
|
||||||
STATE_KEY_BRIGHTNESS = "brightness"
|
|
||||||
STATE_KEY_POSITION = "position"
|
|
||||||
|
|
||||||
DOMAIN = "ads"
|
|
||||||
|
|
||||||
SERVICE_WRITE_DATA_BY_NAME = "write_data_by_name"
|
SERVICE_WRITE_DATA_BY_NAME = "write_data_by_name"
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ 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 CONF_ADS_VAR, DATA_ADS, STATE_KEY_STATE
|
from .const import CONF_ADS_VAR, DATA_ADS, STATE_KEY_STATE
|
||||||
from .entity import AdsEntity
|
from .entity import AdsEntity
|
||||||
|
|
||||||
DEFAULT_NAME = "ADS binary sensor"
|
DEFAULT_NAME = "ADS binary sensor"
|
||||||
@ -37,11 +37,11 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Binary Sensor platform for ADS."""
|
"""Set up the Binary Sensor platform for ADS."""
|
||||||
ads_hub = hass.data.get(DATA_ADS)
|
ads_hub = hass.data[DATA_ADS]
|
||||||
|
|
||||||
ads_var = config[CONF_ADS_VAR]
|
ads_var: str = config[CONF_ADS_VAR]
|
||||||
name = config[CONF_NAME]
|
name: str = config[CONF_NAME]
|
||||||
device_class = config.get(CONF_DEVICE_CLASS)
|
device_class: BinarySensorDeviceClass | None = config.get(CONF_DEVICE_CLASS)
|
||||||
|
|
||||||
ads_sensor = AdsBinarySensor(ads_hub, name, ads_var, device_class)
|
ads_sensor = AdsBinarySensor(ads_hub, name, ads_var, device_class)
|
||||||
add_entities([ads_sensor])
|
add_entities([ads_sensor])
|
||||||
|
18
homeassistant/components/ads/const.py
Normal file
18
homeassistant/components/ads/const.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
"""Support for Automation Device Specification (ADS)."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from homeassistant.util.hass_dict import HassKey
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .hub import AdsHub
|
||||||
|
|
||||||
|
DOMAIN = "ads"
|
||||||
|
|
||||||
|
DATA_ADS: HassKey[AdsHub] = HassKey(DOMAIN)
|
||||||
|
|
||||||
|
CONF_ADS_VAR = "adsvar"
|
||||||
|
|
||||||
|
STATE_KEY_STATE = "state"
|
@ -11,6 +11,7 @@ from homeassistant.components.cover import (
|
|||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
DEVICE_CLASSES_SCHEMA,
|
DEVICE_CLASSES_SCHEMA,
|
||||||
PLATFORM_SCHEMA as COVER_PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA as COVER_PLATFORM_SCHEMA,
|
||||||
|
CoverDeviceClass,
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
CoverEntityFeature,
|
CoverEntityFeature,
|
||||||
)
|
)
|
||||||
@ -20,13 +21,7 @@ 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 .const import CONF_ADS_VAR, DATA_ADS, STATE_KEY_STATE
|
||||||
CONF_ADS_VAR,
|
|
||||||
CONF_ADS_VAR_POSITION,
|
|
||||||
DATA_ADS,
|
|
||||||
STATE_KEY_POSITION,
|
|
||||||
STATE_KEY_STATE,
|
|
||||||
)
|
|
||||||
from .entity import AdsEntity
|
from .entity import AdsEntity
|
||||||
|
|
||||||
DEFAULT_NAME = "ADS Cover"
|
DEFAULT_NAME = "ADS Cover"
|
||||||
@ -35,6 +30,9 @@ CONF_ADS_VAR_SET_POS = "adsvar_set_position"
|
|||||||
CONF_ADS_VAR_OPEN = "adsvar_open"
|
CONF_ADS_VAR_OPEN = "adsvar_open"
|
||||||
CONF_ADS_VAR_CLOSE = "adsvar_close"
|
CONF_ADS_VAR_CLOSE = "adsvar_close"
|
||||||
CONF_ADS_VAR_STOP = "adsvar_stop"
|
CONF_ADS_VAR_STOP = "adsvar_stop"
|
||||||
|
CONF_ADS_VAR_POSITION = "adsvar_position"
|
||||||
|
|
||||||
|
STATE_KEY_POSITION = "position"
|
||||||
|
|
||||||
PLATFORM_SCHEMA = COVER_PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = COVER_PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
@ -59,14 +57,14 @@ def setup_platform(
|
|||||||
"""Set up the cover platform for ADS."""
|
"""Set up the cover platform for ADS."""
|
||||||
ads_hub = hass.data[DATA_ADS]
|
ads_hub = hass.data[DATA_ADS]
|
||||||
|
|
||||||
ads_var_is_closed = config.get(CONF_ADS_VAR)
|
ads_var_is_closed: str | None = config.get(CONF_ADS_VAR)
|
||||||
ads_var_position = config.get(CONF_ADS_VAR_POSITION)
|
ads_var_position: str | None = config.get(CONF_ADS_VAR_POSITION)
|
||||||
ads_var_pos_set = config.get(CONF_ADS_VAR_SET_POS)
|
ads_var_pos_set: str | None = config.get(CONF_ADS_VAR_SET_POS)
|
||||||
ads_var_open = config.get(CONF_ADS_VAR_OPEN)
|
ads_var_open: str | None = config.get(CONF_ADS_VAR_OPEN)
|
||||||
ads_var_close = config.get(CONF_ADS_VAR_CLOSE)
|
ads_var_close: str | None = config.get(CONF_ADS_VAR_CLOSE)
|
||||||
ads_var_stop = config.get(CONF_ADS_VAR_STOP)
|
ads_var_stop: str | None = config.get(CONF_ADS_VAR_STOP)
|
||||||
name = config[CONF_NAME]
|
name: str = config[CONF_NAME]
|
||||||
device_class = config.get(CONF_DEVICE_CLASS)
|
device_class: CoverDeviceClass | None = config.get(CONF_DEVICE_CLASS)
|
||||||
|
|
||||||
add_entities(
|
add_entities(
|
||||||
[
|
[
|
||||||
|
@ -6,7 +6,7 @@ import logging
|
|||||||
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from . import STATE_KEY_STATE
|
from .const import STATE_KEY_STATE
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -19,15 +19,12 @@ 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 .const import CONF_ADS_VAR, DATA_ADS, STATE_KEY_STATE
|
||||||
CONF_ADS_VAR,
|
|
||||||
CONF_ADS_VAR_BRIGHTNESS,
|
|
||||||
DATA_ADS,
|
|
||||||
STATE_KEY_BRIGHTNESS,
|
|
||||||
STATE_KEY_STATE,
|
|
||||||
)
|
|
||||||
from .entity import AdsEntity
|
from .entity import AdsEntity
|
||||||
|
|
||||||
|
CONF_ADS_VAR_BRIGHTNESS = "adsvar_brightness"
|
||||||
|
STATE_KEY_BRIGHTNESS = "brightness"
|
||||||
|
|
||||||
DEFAULT_NAME = "ADS Light"
|
DEFAULT_NAME = "ADS Light"
|
||||||
PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
@ -45,11 +42,11 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the light platform for ADS."""
|
"""Set up the light platform for ADS."""
|
||||||
ads_hub = hass.data.get(DATA_ADS)
|
ads_hub = hass.data[DATA_ADS]
|
||||||
|
|
||||||
ads_var_enable = config[CONF_ADS_VAR]
|
ads_var_enable: str = config[CONF_ADS_VAR]
|
||||||
ads_var_brightness = config.get(CONF_ADS_VAR_BRIGHTNESS)
|
ads_var_brightness: str | None = config.get(CONF_ADS_VAR_BRIGHTNESS)
|
||||||
name = config[CONF_NAME]
|
name: str = config[CONF_NAME]
|
||||||
|
|
||||||
add_entities([AdsLight(ads_hub, ads_var_enable, ads_var_brightness, name)])
|
add_entities([AdsLight(ads_hub, ads_var_enable, ads_var_brightness, name)])
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
||||||
|
|
||||||
from .. import ads
|
from .. import ads
|
||||||
from . import ADS_TYPEMAP, CONF_ADS_FACTOR, CONF_ADS_TYPE, CONF_ADS_VAR, STATE_KEY_STATE
|
from . import ADS_TYPEMAP, CONF_ADS_FACTOR, CONF_ADS_TYPE
|
||||||
|
from .const import CONF_ADS_VAR, DATA_ADS, STATE_KEY_STATE
|
||||||
from .entity import AdsEntity
|
from .entity import AdsEntity
|
||||||
|
|
||||||
DEFAULT_NAME = "ADS sensor"
|
DEFAULT_NAME = "ADS sensor"
|
||||||
@ -60,14 +61,15 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up an ADS sensor device."""
|
"""Set up an ADS sensor device."""
|
||||||
ads_hub: ads.AdsHub = hass.data[ads.DATA_ADS]
|
ads_hub = hass.data[DATA_ADS]
|
||||||
ads_var = config[CONF_ADS_VAR]
|
|
||||||
ads_type = config[CONF_ADS_TYPE]
|
ads_var: str = config[CONF_ADS_VAR]
|
||||||
name = config[CONF_NAME]
|
ads_type: str = config[CONF_ADS_TYPE]
|
||||||
factor = config.get(CONF_ADS_FACTOR)
|
name: str = config[CONF_NAME]
|
||||||
device_class = config.get(CONF_DEVICE_CLASS)
|
factor: int | None = config.get(CONF_ADS_FACTOR)
|
||||||
state_class = config.get(CONF_STATE_CLASS)
|
device_class: SensorDeviceClass | None = config.get(CONF_DEVICE_CLASS)
|
||||||
unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT)
|
state_class: SensorStateClass | None = config.get(CONF_STATE_CLASS)
|
||||||
|
unit_of_measurement: str | None = config.get(CONF_UNIT_OF_MEASUREMENT)
|
||||||
|
|
||||||
entity = AdsSensor(
|
entity = AdsSensor(
|
||||||
ads_hub,
|
ads_hub,
|
||||||
|
@ -17,7 +17,7 @@ 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 CONF_ADS_VAR, DATA_ADS, STATE_KEY_STATE
|
from .const import CONF_ADS_VAR, DATA_ADS, STATE_KEY_STATE
|
||||||
from .entity import AdsEntity
|
from .entity import AdsEntity
|
||||||
|
|
||||||
DEFAULT_NAME = "ADS Switch"
|
DEFAULT_NAME = "ADS Switch"
|
||||||
@ -37,10 +37,10 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up switch platform for ADS."""
|
"""Set up switch platform for ADS."""
|
||||||
ads_hub = hass.data.get(DATA_ADS)
|
ads_hub = hass.data[DATA_ADS]
|
||||||
|
|
||||||
name = config[CONF_NAME]
|
name: str = config[CONF_NAME]
|
||||||
ads_var = config[CONF_ADS_VAR]
|
ads_var: str = config[CONF_ADS_VAR]
|
||||||
|
|
||||||
add_entities([AdsSwitch(ads_hub, name, ads_var)])
|
add_entities([AdsSwitch(ads_hub, name, ads_var)])
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ 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 CONF_ADS_VAR, DATA_ADS
|
from .const import CONF_ADS_VAR, DATA_ADS
|
||||||
from .entity import AdsEntity
|
from .entity import AdsEntity
|
||||||
from .hub import AdsHub
|
from .hub import AdsHub
|
||||||
|
|
||||||
@ -40,10 +40,11 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up an ADS valve device."""
|
"""Set up an ADS valve device."""
|
||||||
ads_hub: AdsHub = hass.data[DATA_ADS]
|
ads_hub = hass.data[DATA_ADS]
|
||||||
ads_var = config[CONF_ADS_VAR]
|
|
||||||
name = config[CONF_NAME]
|
ads_var: str = config[CONF_ADS_VAR]
|
||||||
device_class = config.get(CONF_DEVICE_CLASS)
|
name: str = config[CONF_NAME]
|
||||||
|
device_class: ValveDeviceClass | None = config.get(CONF_DEVICE_CLASS)
|
||||||
supported_features: ValveEntityFeature = (
|
supported_features: ValveEntityFeature = (
|
||||||
ValveEntityFeature.OPEN | ValveEntityFeature.CLOSE
|
ValveEntityFeature.OPEN | ValveEntityFeature.CLOSE
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user