Use new Platform enum in KNX (#60902)

This commit is contained in:
Marvin Wichmann 2021-12-03 18:29:38 +01:00 committed by GitHub
parent 77cd751543
commit 3baa7b679d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 118 additions and 147 deletions

View file

@ -47,7 +47,7 @@ from .const import (
DATA_KNX_CONFIG,
DOMAIN,
KNX_ADDRESS,
SupportedPlatforms,
SUPPORTED_PLATFORMS,
)
from .expose import KNXExposeSensor, KNXExposeTime, create_knx_exposure
from .schema import (
@ -251,16 +251,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
hass.config_entries.async_setup_platforms(
entry,
[platform.value for platform in SupportedPlatforms if platform.value in config],
entry, [platform for platform in SUPPORTED_PLATFORMS if platform in config]
)
# set up notify platform, no entry support for notify component yet,
# have to use discovery to load platform.
if NotifySchema.PLATFORM_NAME in conf:
if NotifySchema.PLATFORM in conf:
hass.async_create_task(
discovery.async_load_platform(
hass, "notify", DOMAIN, conf[NotifySchema.PLATFORM_NAME], config
hass, "notify", DOMAIN, conf[NotifySchema.PLATFORM], config
)
)
@ -310,9 +309,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
unload_ok = await hass.config_entries.async_unload_platforms(
entry,
[
platform.value
for platform in SupportedPlatforms
if platform.value in hass.data[DATA_KNX_CONFIG]
platform
for platform in SUPPORTED_PLATFORMS
if platform in hass.data[DATA_KNX_CONFIG]
],
)
if unload_ok:

View file

@ -15,19 +15,14 @@ from homeassistant.const import (
STATE_ON,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType
from .const import (
ATTR_COUNTER,
ATTR_SOURCE,
DATA_KNX_CONFIG,
DOMAIN,
SupportedPlatforms,
)
from .const import ATTR_COUNTER, ATTR_SOURCE, DATA_KNX_CONFIG, DOMAIN
from .knx_entity import KnxEntity
from .schema import BinarySensorSchema
@ -43,7 +38,7 @@ async def async_setup_entry(
async_add_entities(
KNXBinarySensor(xknx, entity_config)
for entity_config in config[SupportedPlatforms.BINARY_SENSOR.value]
for entity_config in config[Platform.BINARY_SENSOR]
)

View file

@ -6,7 +6,7 @@ from xknx.devices import RawValue as XknxRawValue
from homeassistant import config_entries
from homeassistant.components.button import ButtonEntity
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType
@ -17,7 +17,6 @@ from .const import (
DATA_KNX_CONFIG,
DOMAIN,
KNX_ADDRESS,
SupportedPlatforms,
)
from .knx_entity import KnxEntity
@ -32,8 +31,7 @@ async def async_setup_entry(
config: ConfigType = hass.data[DATA_KNX_CONFIG]
async_add_entities(
KNXButton(xknx, entity_config)
for entity_config in config[SupportedPlatforms.BUTTON.value]
KNXButton(xknx, entity_config) for entity_config in config[Platform.BUTTON]
)

View file

@ -22,6 +22,7 @@ from homeassistant.const import (
CONF_ENTITY_CATEGORY,
CONF_NAME,
TEMP_CELSIUS,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -33,7 +34,6 @@ from .const import (
DATA_KNX_CONFIG,
DOMAIN,
PRESET_MODES,
SupportedPlatforms,
)
from .knx_entity import KnxEntity
from .schema import ClimateSchema
@ -50,9 +50,7 @@ async def async_setup_entry(
) -> None:
"""Set up climate(s) for KNX platform."""
xknx: XKNX = hass.data[DOMAIN].xknx
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][
SupportedPlatforms.CLIMATE.value
]
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][Platform.CLIMATE]
async_add_entities(KNXClimate(xknx, entity_config) for entity_config in config)

View file

@ -20,6 +20,7 @@ from homeassistant.components.climate.const import (
PRESET_NONE,
PRESET_SLEEP,
)
from homeassistant.const import Platform
DOMAIN: Final = "knx"
@ -54,23 +55,21 @@ class ColorTempModes(Enum):
RELATIVE = "DPT-5.001"
class SupportedPlatforms(Enum):
"""Supported platforms."""
BINARY_SENSOR = "binary_sensor"
BUTTON = "button"
CLIMATE = "climate"
COVER = "cover"
FAN = "fan"
LIGHT = "light"
NOTIFY = "notify"
NUMBER = "number"
SCENE = "scene"
SELECT = "select"
SENSOR = "sensor"
SWITCH = "switch"
WEATHER = "weather"
SUPPORTED_PLATFORMS: Final = [
Platform.BINARY_SENSOR,
Platform.BUTTON,
Platform.CLIMATE,
Platform.COVER,
Platform.FAN,
Platform.LIGHT,
Platform.NOTIFY,
Platform.NUMBER,
Platform.SCENE,
Platform.SELECT,
Platform.SENSOR,
Platform.SWITCH,
Platform.WEATHER,
]
# Map KNX controller modes to HA modes. This list might not be complete.
CONTROLLER_MODES: Final = {

View file

@ -23,13 +23,18 @@ from homeassistant.components.cover import (
SUPPORT_STOP_TILT,
CoverEntity,
)
from homeassistant.const import CONF_DEVICE_CLASS, CONF_ENTITY_CATEGORY, CONF_NAME
from homeassistant.const import (
CONF_DEVICE_CLASS,
CONF_ENTITY_CATEGORY,
CONF_NAME,
Platform,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_utc_time_change
from homeassistant.helpers.typing import ConfigType
from .const import DATA_KNX_CONFIG, DOMAIN, SupportedPlatforms
from .const import DATA_KNX_CONFIG, DOMAIN
from .knx_entity import KnxEntity
from .schema import CoverSchema
@ -41,9 +46,7 @@ async def async_setup_entry(
) -> None:
"""Set up cover(s) for KNX platform."""
xknx: XKNX = hass.data[DOMAIN].xknx
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][
SupportedPlatforms.COVER.value
]
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][Platform.COVER]
async_add_entities(KNXCover(xknx, entity_config) for entity_config in config)

View file

@ -9,7 +9,7 @@ from xknx.devices import Fan as XknxFan
from homeassistant import config_entries
from homeassistant.components.fan import SUPPORT_OSCILLATE, SUPPORT_SET_SPEED, FanEntity
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType
@ -19,7 +19,7 @@ from homeassistant.util.percentage import (
ranged_value_to_percentage,
)
from .const import DATA_KNX_CONFIG, DOMAIN, KNX_ADDRESS, SupportedPlatforms
from .const import DATA_KNX_CONFIG, DOMAIN, KNX_ADDRESS
from .knx_entity import KnxEntity
from .schema import FanSchema
@ -33,7 +33,7 @@ async def async_setup_entry(
) -> None:
"""Set up fan(s) for KNX platform."""
xknx: XKNX = hass.data[DOMAIN].xknx
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][SupportedPlatforms.FAN.value]
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][Platform.FAN]
async_add_entities(KNXFan(xknx, entity_config) for entity_config in config)

View file

@ -23,19 +23,13 @@ from homeassistant.components.light import (
COLOR_MODE_XY,
LightEntity,
)
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType
import homeassistant.util.color as color_util
from .const import (
DATA_KNX_CONFIG,
DOMAIN,
KNX_ADDRESS,
ColorTempModes,
SupportedPlatforms,
)
from .const import DATA_KNX_CONFIG, DOMAIN, KNX_ADDRESS, ColorTempModes
from .knx_entity import KnxEntity
from .schema import LightSchema
@ -47,9 +41,7 @@ async def async_setup_entry(
) -> None:
"""Set up light(s) for KNX platform."""
xknx: XKNX = hass.data[DOMAIN].xknx
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][
SupportedPlatforms.LIGHT.value
]
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][Platform.LIGHT]
async_add_entities(KNXLight(xknx, entity_config) for entity_config in config)

View file

@ -15,6 +15,7 @@ from homeassistant.const import (
CONF_TYPE,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -27,7 +28,6 @@ from .const import (
DATA_KNX_CONFIG,
DOMAIN,
KNX_ADDRESS,
SupportedPlatforms,
)
from .knx_entity import KnxEntity
from .schema import NumberSchema
@ -40,9 +40,7 @@ async def async_setup_entry(
) -> None:
"""Set up number(s) for KNX platform."""
xknx: XKNX = hass.data[DOMAIN].xknx
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][
SupportedPlatforms.NUMBER.value
]
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][Platform.NUMBER]
async_add_entities(KNXNumber(xknx, entity_config) for entity_config in config)

View file

@ -8,12 +8,12 @@ from xknx.devices import Scene as XknxScene
from homeassistant import config_entries
from homeassistant.components.scene import Scene
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType
from .const import DATA_KNX_CONFIG, DOMAIN, KNX_ADDRESS, SupportedPlatforms
from .const import DATA_KNX_CONFIG, DOMAIN, KNX_ADDRESS
from .knx_entity import KnxEntity
from .schema import SceneSchema
@ -25,9 +25,7 @@ async def async_setup_entry(
) -> None:
"""Set up scene(s) for KNX platform."""
xknx: XKNX = hass.data[DOMAIN].xknx
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][
SupportedPlatforms.SCENE.value
]
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][Platform.SCENE]
async_add_entities(KNXScene(xknx, entity_config) for entity_config in config)

View file

@ -30,6 +30,7 @@ from homeassistant.const import (
CONF_NAME,
CONF_PORT,
CONF_TYPE,
Platform,
)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import ENTITY_CATEGORIES_SCHEMA
@ -50,7 +51,6 @@ from .const import (
KNX_ADDRESS,
PRESET_MODES,
ColorTempModes,
SupportedPlatforms,
)
##################
@ -275,14 +275,14 @@ class EventSchema:
class KNXPlatformSchema(ABC):
"""Voluptuous schema for KNX platform entity configuration."""
PLATFORM_NAME: ClassVar[str]
PLATFORM: ClassVar[Platform | str]
ENTITY_SCHEMA: ClassVar[vol.Schema]
@classmethod
def platform_node(cls) -> dict[vol.Optional, vol.All]:
"""Return a schema node for the platform."""
return {
vol.Optional(cls.PLATFORM_NAME): vol.All(
vol.Optional(str(cls.PLATFORM)): vol.All(
cv.ensure_list, [cls.ENTITY_SCHEMA]
)
}
@ -291,7 +291,7 @@ class KNXPlatformSchema(ABC):
class BinarySensorSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX binary sensors."""
PLATFORM_NAME = SupportedPlatforms.BINARY_SENSOR.value
PLATFORM = Platform.BINARY_SENSOR
CONF_STATE_ADDRESS = CONF_STATE_ADDRESS
CONF_SYNC_STATE = CONF_SYNC_STATE
@ -327,7 +327,7 @@ class BinarySensorSchema(KNXPlatformSchema):
class ButtonSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX buttons."""
PLATFORM_NAME = SupportedPlatforms.BUTTON.value
PLATFORM = Platform.BUTTON
CONF_VALUE = "value"
DEFAULT_NAME = "KNX Button"
@ -388,7 +388,7 @@ class ButtonSchema(KNXPlatformSchema):
class ClimateSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX climate devices."""
PLATFORM_NAME = SupportedPlatforms.CLIMATE.value
PLATFORM = Platform.CLIMATE
CONF_ACTIVE_STATE_ADDRESS = "active_state_address"
CONF_SETPOINT_SHIFT_ADDRESS = "setpoint_shift_address"
@ -507,7 +507,7 @@ class ClimateSchema(KNXPlatformSchema):
class CoverSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX covers."""
PLATFORM_NAME = SupportedPlatforms.COVER.value
PLATFORM = Platform.COVER
CONF_MOVE_LONG_ADDRESS = "move_long_address"
CONF_MOVE_SHORT_ADDRESS = "move_short_address"
@ -562,7 +562,7 @@ class CoverSchema(KNXPlatformSchema):
class ExposeSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX exposures."""
PLATFORM_NAME = CONF_KNX_EXPOSE
PLATFORM = CONF_KNX_EXPOSE
CONF_KNX_EXPOSE_TYPE = CONF_TYPE
CONF_KNX_EXPOSE_ATTRIBUTE = "attribute"
@ -599,7 +599,7 @@ class ExposeSchema(KNXPlatformSchema):
class FanSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX fans."""
PLATFORM_NAME = SupportedPlatforms.FAN.value
PLATFORM = Platform.FAN
CONF_STATE_ADDRESS = CONF_STATE_ADDRESS
CONF_OSCILLATION_ADDRESS = "oscillation_address"
@ -624,7 +624,7 @@ class FanSchema(KNXPlatformSchema):
class LightSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX lights."""
PLATFORM_NAME = SupportedPlatforms.LIGHT.value
PLATFORM = Platform.LIGHT
CONF_STATE_ADDRESS = CONF_STATE_ADDRESS
CONF_BRIGHTNESS_ADDRESS = "brightness_address"
@ -764,7 +764,7 @@ class LightSchema(KNXPlatformSchema):
class NotifySchema(KNXPlatformSchema):
"""Voluptuous schema for KNX notifications."""
PLATFORM_NAME = SupportedPlatforms.NOTIFY.value
PLATFORM = Platform.NOTIFY
DEFAULT_NAME = "KNX Notify"
@ -779,7 +779,7 @@ class NotifySchema(KNXPlatformSchema):
class NumberSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX numbers."""
PLATFORM_NAME = SupportedPlatforms.NUMBER.value
PLATFORM = Platform.NUMBER
CONF_MAX = "max"
CONF_MIN = "min"
@ -810,7 +810,7 @@ class NumberSchema(KNXPlatformSchema):
class SceneSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX scenes."""
PLATFORM_NAME = SupportedPlatforms.SCENE.value
PLATFORM = Platform.SCENE
CONF_SCENE_NUMBER = "scene_number"
@ -830,7 +830,7 @@ class SceneSchema(KNXPlatformSchema):
class SelectSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX selects."""
PLATFORM_NAME = SupportedPlatforms.SELECT.value
PLATFORM = Platform.SELECT
CONF_OPTION = "option"
CONF_OPTIONS = "options"
@ -863,7 +863,7 @@ class SelectSchema(KNXPlatformSchema):
class SensorSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX sensors."""
PLATFORM_NAME = SupportedPlatforms.SENSOR.value
PLATFORM = Platform.SENSOR
CONF_ALWAYS_CALLBACK = "always_callback"
CONF_STATE_ADDRESS = CONF_STATE_ADDRESS
@ -886,7 +886,7 @@ class SensorSchema(KNXPlatformSchema):
class SwitchSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX switches."""
PLATFORM_NAME = SupportedPlatforms.SWITCH.value
PLATFORM = Platform.SWITCH
CONF_INVERT = CONF_INVERT
CONF_STATE_ADDRESS = CONF_STATE_ADDRESS
@ -907,7 +907,7 @@ class SwitchSchema(KNXPlatformSchema):
class WeatherSchema(KNXPlatformSchema):
"""Voluptuous schema for KNX weather station."""
PLATFORM_NAME = SupportedPlatforms.WEATHER.value
PLATFORM = Platform.WEATHER
CONF_SYNC_STATE = CONF_SYNC_STATE
CONF_KNX_TEMPERATURE_ADDRESS = "address_temperature"

View file

@ -11,6 +11,7 @@ from homeassistant.const import (
CONF_NAME,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -26,7 +27,6 @@ from .const import (
DATA_KNX_CONFIG,
DOMAIN,
KNX_ADDRESS,
SupportedPlatforms,
)
from .knx_entity import KnxEntity
from .schema import SelectSchema
@ -39,9 +39,7 @@ async def async_setup_entry(
) -> None:
"""Set up select(s) for KNX platform."""
xknx: XKNX = hass.data[DOMAIN].xknx
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][
SupportedPlatforms.SELECT.value
]
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][Platform.SELECT]
async_add_entities(KNXSelect(xknx, entity_config) for entity_config in config)

View file

@ -12,12 +12,12 @@ from homeassistant.components.sensor import (
DEVICE_CLASSES,
SensorEntity,
)
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, CONF_TYPE
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, CONF_TYPE, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, StateType
from .const import ATTR_SOURCE, DATA_KNX_CONFIG, DOMAIN, SupportedPlatforms
from .const import ATTR_SOURCE, DATA_KNX_CONFIG, DOMAIN
from .knx_entity import KnxEntity
from .schema import SensorSchema
@ -29,9 +29,7 @@ async def async_setup_entry(
) -> None:
"""Set up sensor(s) for KNX platform."""
xknx: XKNX = hass.data[DOMAIN].xknx
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][
SupportedPlatforms.SENSOR.value
]
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][Platform.SENSOR]
async_add_entities(KNXSensor(xknx, entity_config) for entity_config in config)

View file

@ -14,19 +14,14 @@ from homeassistant.const import (
STATE_ON,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType
from .const import (
CONF_RESPOND_TO_READ,
DATA_KNX_CONFIG,
DOMAIN,
KNX_ADDRESS,
SupportedPlatforms,
)
from .const import CONF_RESPOND_TO_READ, DATA_KNX_CONFIG, DOMAIN, KNX_ADDRESS
from .knx_entity import KnxEntity
from .schema import SwitchSchema
@ -38,9 +33,7 @@ async def async_setup_entry(
) -> None:
"""Set up switch(es) for KNX platform."""
xknx: XKNX = hass.data[DOMAIN].xknx
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][
SupportedPlatforms.SWITCH.value
]
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][Platform.SWITCH]
async_add_entities(KNXSwitch(xknx, entity_config) for entity_config in config)

View file

@ -6,12 +6,12 @@ from xknx.devices import Weather as XknxWeather
from homeassistant import config_entries
from homeassistant.components.weather import WeatherEntity
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, TEMP_CELSIUS
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, TEMP_CELSIUS, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType
from .const import DATA_KNX_CONFIG, DOMAIN, SupportedPlatforms
from .const import DATA_KNX_CONFIG, DOMAIN
from .knx_entity import KnxEntity
from .schema import WeatherSchema
@ -23,9 +23,7 @@ async def async_setup_entry(
) -> None:
"""Set up switch(es) for KNX platform."""
xknx: XKNX = hass.data[DOMAIN].xknx
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][
SupportedPlatforms.WEATHER.value
]
config: list[ConfigType] = hass.data[DATA_KNX_CONFIG][Platform.WEATHER]
async_add_entities(KNXWeather(xknx, entity_config) for entity_config in config)

View file

@ -26,7 +26,7 @@ async def test_binary_sensor_entity_category(hass: HomeAssistant, knx: KNXTestKi
"""Test KNX binary sensor entity category."""
await knx.setup_integration(
{
BinarySensorSchema.PLATFORM_NAME: [
BinarySensorSchema.PLATFORM: [
{
CONF_NAME: "test_normal",
CONF_STATE_ADDRESS: "1/1/1",
@ -49,7 +49,7 @@ async def test_binary_sensor(hass: HomeAssistant, knx: KNXTestKit):
"""Test KNX binary sensor and inverted binary_sensor."""
await knx.setup_integration(
{
BinarySensorSchema.PLATFORM_NAME: [
BinarySensorSchema.PLATFORM: [
{
CONF_NAME: "test_normal",
CONF_STATE_ADDRESS: "1/1/1",
@ -104,7 +104,7 @@ async def test_binary_sensor_ignore_internal_state(
await knx.setup_integration(
{
BinarySensorSchema.PLATFORM_NAME: [
BinarySensorSchema.PLATFORM: [
{
CONF_NAME: "test_normal",
CONF_STATE_ADDRESS: "1/1/1",
@ -156,7 +156,7 @@ async def test_binary_sensor_counter(hass: HomeAssistant, knx: KNXTestKit):
await knx.setup_integration(
{
BinarySensorSchema.PLATFORM_NAME: [
BinarySensorSchema.PLATFORM: [
{
CONF_NAME: "test",
CONF_STATE_ADDRESS: "2/2/2",
@ -223,7 +223,7 @@ async def test_binary_sensor_reset(hass: HomeAssistant, knx: KNXTestKit):
await knx.setup_integration(
{
BinarySensorSchema.PLATFORM_NAME: [
BinarySensorSchema.PLATFORM: [
{
CONF_NAME: "test",
CONF_STATE_ADDRESS: "2/2/2",
@ -259,7 +259,7 @@ async def test_binary_sensor_restore_and_respond(hass, knx):
):
await knx.setup_integration(
{
BinarySensorSchema.PLATFORM_NAME: [
BinarySensorSchema.PLATFORM: [
{
CONF_NAME: "test",
CONF_STATE_ADDRESS: _ADDRESS,
@ -291,7 +291,7 @@ async def test_binary_sensor_restore_invert(hass, knx):
):
await knx.setup_integration(
{
BinarySensorSchema.PLATFORM_NAME: [
BinarySensorSchema.PLATFORM: [
{
CONF_NAME: "test",
CONF_STATE_ADDRESS: _ADDRESS,

View file

@ -21,7 +21,7 @@ async def test_button_simple(hass: HomeAssistant, knx: KNXTestKit):
events = async_capture_events(hass, "state_changed")
await knx.setup_integration(
{
ButtonSchema.PLATFORM_NAME: {
ButtonSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: "1/2/3",
}
@ -57,7 +57,7 @@ async def test_button_raw(hass: HomeAssistant, knx: KNXTestKit):
"""Test KNX button with raw payload."""
await knx.setup_integration(
{
ButtonSchema.PLATFORM_NAME: {
ButtonSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: "1/2/3",
CONF_PAYLOAD: False,
@ -76,7 +76,7 @@ async def test_button_type(hass: HomeAssistant, knx: KNXTestKit):
"""Test KNX button with encoded payload."""
await knx.setup_integration(
{
ButtonSchema.PLATFORM_NAME: {
ButtonSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: "1/2/3",
ButtonSchema.CONF_VALUE: 21.5,

View file

@ -11,7 +11,7 @@ async def test_fan_percent(hass: HomeAssistant, knx: KNXTestKit):
"""Test KNX fan with percentage speed."""
await knx.setup_integration(
{
FanSchema.PLATFORM_NAME: {
FanSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: "1/2/3",
}
@ -56,7 +56,7 @@ async def test_fan_step(hass: HomeAssistant, knx: KNXTestKit):
"""Test KNX fan with speed steps."""
await knx.setup_integration(
{
FanSchema.PLATFORM_NAME: {
FanSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: "1/2/3",
FanSchema.CONF_MAX_STEP: 4,
@ -109,7 +109,7 @@ async def test_fan_oscillation(hass: HomeAssistant, knx: KNXTestKit):
"""Test KNX fan oscillation."""
await knx.setup_integration(
{
FanSchema.PLATFORM_NAME: {
FanSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: "1/1/1",
FanSchema.CONF_OSCILLATION_ADDRESS: "2/2/2",

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from datetime import timedelta
from xknx.core import XknxConnectionState
from xknx.devices.light import Light as XknxLight
from homeassistant.components.knx.const import CONF_STATE_ADDRESS, KNX_ADDRESS
@ -35,7 +36,7 @@ async def test_light_simple(hass: HomeAssistant, knx: KNXTestKit):
test_address = "1/1/1"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: {
LightSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: test_address,
}
@ -86,7 +87,7 @@ async def test_light_brightness(hass: HomeAssistant, knx: KNXTestKit):
test_brightness_state = "1/1/3"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: {
LightSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: test_address,
LightSchema.CONF_BRIGHTNESS_ADDRESS: test_brightness,
@ -96,6 +97,9 @@ async def test_light_brightness(hass: HomeAssistant, knx: KNXTestKit):
)
# StateUpdater initialize state
await knx.assert_read(test_brightness_state)
await knx.xknx.connection_manager.connection_state_changed(
XknxConnectionState.CONNECTED
)
# turn on light via brightness
await hass.services.async_call(
"light",
@ -139,7 +143,7 @@ async def test_light_color_temp_absolute(hass: HomeAssistant, knx: KNXTestKit):
test_ct_state = "1/1/6"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: [
LightSchema.PLATFORM: [
{
CONF_NAME: "test",
KNX_ADDRESS: test_address,
@ -193,7 +197,7 @@ async def test_light_color_temp_relative(hass: HomeAssistant, knx: KNXTestKit):
test_ct_state = "1/1/6"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: [
LightSchema.PLATFORM: [
{
CONF_NAME: "test",
KNX_ADDRESS: test_address,
@ -251,7 +255,7 @@ async def test_light_hs_color(hass: HomeAssistant, knx: KNXTestKit):
test_sat_state = "1/1/8"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: [
LightSchema.PLATFORM: [
{
CONF_NAME: "test",
KNX_ADDRESS: test_address,
@ -335,7 +339,7 @@ async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit):
test_xyy_state = "1/1/6"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: [
LightSchema.PLATFORM: [
{
CONF_NAME: "test",
KNX_ADDRESS: test_address,
@ -410,7 +414,7 @@ async def test_light_xyy_color_with_brightness(hass: HomeAssistant, knx: KNXTest
test_xyy_state = "1/1/6"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: [
LightSchema.PLATFORM: [
{
CONF_NAME: "test",
KNX_ADDRESS: test_address,
@ -488,7 +492,7 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit):
test_blue_state = "1/1/8"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: [
LightSchema.PLATFORM: [
{
CONF_NAME: "test",
LightSchema.CONF_INDIVIDUAL_COLORS: {
@ -636,7 +640,7 @@ async def test_light_rgbw_individual(hass: HomeAssistant, knx: KNXTestKit):
test_white_state = "1/1/10"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: [
LightSchema.PLATFORM: [
{
CONF_NAME: "test",
LightSchema.CONF_INDIVIDUAL_COLORS: {
@ -810,7 +814,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit):
test_rgb_state = "1/1/6"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: [
LightSchema.PLATFORM: [
{
CONF_NAME: "test",
KNX_ADDRESS: test_address,
@ -918,7 +922,7 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit):
test_rgbw_state = "1/1/6"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: [
LightSchema.PLATFORM: [
{
CONF_NAME: "test",
KNX_ADDRESS: test_address,
@ -1031,7 +1035,7 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit):
test_rgbw_state = "1/1/6"
await knx.setup_integration(
{
LightSchema.PLATFORM_NAME: [
LightSchema.PLATFORM: [
{
CONF_NAME: "test",
KNX_ADDRESS: test_address,

View file

@ -16,7 +16,7 @@ async def test_number_set_value(hass: HomeAssistant, knx: KNXTestKit):
test_address = "1/1/1"
await knx.setup_integration(
{
NumberSchema.PLATFORM_NAME: {
NumberSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: test_address,
CONF_TYPE: "percent",
@ -72,7 +72,7 @@ async def test_number_restore_and_respond(hass: HomeAssistant, knx: KNXTestKit):
):
await knx.setup_integration(
{
NumberSchema.PLATFORM_NAME: {
NumberSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: [test_address, test_passive_address],
CONF_RESPOND_TO_READ: True,

View file

@ -19,7 +19,7 @@ async def test_activate_knx_scene(hass: HomeAssistant, knx: KNXTestKit):
"""Test KNX scene."""
await knx.setup_integration(
{
SceneSchema.PLATFORM_NAME: [
SceneSchema.PLATFORM: [
{
CONF_NAME: "test",
SceneSchema.CONF_SCENE_NUMBER: 24,

View file

@ -28,7 +28,7 @@ async def test_select_dpt_2_simple(hass: HomeAssistant, knx: KNXTestKit):
test_address = "1/1/1"
await knx.setup_integration(
{
SelectSchema.PLATFORM_NAME: {
SelectSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: test_address,
CONF_SYNC_STATE: False,
@ -105,7 +105,7 @@ async def test_select_dpt_2_restore(hass: HomeAssistant, knx: KNXTestKit):
):
await knx.setup_integration(
{
SelectSchema.PLATFORM_NAME: {
SelectSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: [test_address, test_passive_address],
CONF_RESPOND_TO_READ: True,
@ -143,7 +143,7 @@ async def test_select_dpt_20_103_all_options(hass: HomeAssistant, knx: KNXTestKi
await knx.setup_integration(
{
SelectSchema.PLATFORM_NAME: {
SelectSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: [test_address, test_passive_address],
CONF_STATE_ADDRESS: test_state_address,

View file

@ -14,7 +14,7 @@ async def test_sensor(hass: HomeAssistant, knx: KNXTestKit):
await knx.setup_integration(
{
SensorSchema.PLATFORM_NAME: {
SensorSchema.PLATFORM: {
CONF_NAME: "test",
CONF_STATE_ADDRESS: "1/1/1",
CONF_TYPE: "current", # 2 byte unsigned int
@ -47,7 +47,7 @@ async def test_always_callback(hass: HomeAssistant, knx: KNXTestKit):
events = async_capture_events(hass, "state_changed")
await knx.setup_integration(
{
SensorSchema.PLATFORM_NAME: [
SensorSchema.PLATFORM: [
{
CONF_NAME: "test_normal",
CONF_STATE_ADDRESS: "1/1/1",

View file

@ -17,7 +17,7 @@ async def test_switch_simple(hass: HomeAssistant, knx: KNXTestKit):
"""Test simple KNX switch."""
await knx.setup_integration(
{
SwitchSchema.PLATFORM_NAME: {
SwitchSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: "1/2/3",
}
@ -59,7 +59,7 @@ async def test_switch_state(hass: HomeAssistant, knx: KNXTestKit):
await knx.setup_integration(
{
SwitchSchema.PLATFORM_NAME: {
SwitchSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: _ADDRESS,
CONF_STATE_ADDRESS: _STATE_ADDRESS,
@ -122,7 +122,7 @@ async def test_switch_restore_and_respond(hass, knx):
):
await knx.setup_integration(
{
SwitchSchema.PLATFORM_NAME: {
SwitchSchema.PLATFORM: {
CONF_NAME: "test",
KNX_ADDRESS: _ADDRESS,
CONF_RESPOND_TO_READ: True,

View file

@ -17,7 +17,7 @@ async def test_weather(hass: HomeAssistant, knx: KNXTestKit):
await knx.setup_integration(
{
WeatherSchema.PLATFORM_NAME: {
WeatherSchema.PLATFORM: {
CONF_NAME: "test",
WeatherSchema.CONF_KNX_WIND_ALARM_ADDRESS: "1/1/1",
WeatherSchema.CONF_KNX_RAIN_ALARM_ADDRESS: "1/1/2",