mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Use PLATFORM_SCHEMA_BASE as base schema for additional components. (#20578)
* Disable extra=vol.ALLOW_EXTRA for additional platforms. * Remove PLATFORM_SCHEMA_2 * Add entity_namespace to base platform schema
This commit is contained in:
parent
154b401d0a
commit
b1faad0a50
@ -8,7 +8,8 @@ from datetime import timedelta
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -14,7 +14,7 @@ from homeassistant.const import (
|
|||||||
SERVICE_ALARM_DISARM, SERVICE_ALARM_ARM_HOME, SERVICE_ALARM_ARM_AWAY,
|
SERVICE_ALARM_DISARM, SERVICE_ALARM_ARM_HOME, SERVICE_ALARM_ARM_AWAY,
|
||||||
SERVICE_ALARM_ARM_NIGHT, SERVICE_ALARM_ARM_CUSTOM_BYPASS)
|
SERVICE_ALARM_ARM_NIGHT, SERVICE_ALARM_ARM_CUSTOM_BYPASS)
|
||||||
from homeassistant.helpers.config_validation import ( # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
PLATFORM_SCHEMA_BASE, PLATFORM_SCHEMA_2 as PLATFORM_SCHEMA)
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
|
@ -13,7 +13,8 @@ import voluptuous as vol
|
|||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.const import (STATE_ON, STATE_OFF)
|
from homeassistant.const import (STATE_ON, STATE_OFF)
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
|
|
||||||
DOMAIN = 'binary_sensor'
|
DOMAIN = 'binary_sensor'
|
||||||
SCAN_INTERVAL = timedelta(seconds=30)
|
SCAN_INTERVAL = timedelta(seconds=30)
|
||||||
|
@ -13,7 +13,8 @@ from aiohttp import web
|
|||||||
from homeassistant.components.google import (
|
from homeassistant.components.google import (
|
||||||
CONF_OFFSET, CONF_DEVICE_ID, CONF_NAME)
|
CONF_OFFSET, CONF_DEVICE_ID, CONF_NAME)
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON
|
from homeassistant.const import STATE_OFF, STATE_ON
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
from homeassistant.helpers.config_validation import time_period_str
|
from homeassistant.helpers.config_validation import time_period_str
|
||||||
from homeassistant.helpers.entity import Entity, generate_entity_id
|
from homeassistant.helpers.entity import Entity, generate_entity_id
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
|
@ -25,7 +25,8 @@ from homeassistant.exceptions import HomeAssistantError
|
|||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
from homeassistant.components.http import HomeAssistantView, KEY_AUTHENTICATED
|
from homeassistant.components.http import HomeAssistantView, KEY_AUTHENTICATED
|
||||||
from homeassistant.components import websocket_api
|
from homeassistant.components import websocket_api
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
@ -14,7 +14,8 @@ from homeassistant.helpers.temperature import display_temp as show_temp
|
|||||||
from homeassistant.util.temperature import convert as convert_temperature
|
from homeassistant.util.temperature import convert as convert_temperature
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID, ATTR_TEMPERATURE, SERVICE_TURN_ON, SERVICE_TURN_OFF,
|
ATTR_ENTITY_ID, ATTR_TEMPERATURE, SERVICE_TURN_ON, SERVICE_TURN_OFF,
|
||||||
|
@ -13,7 +13,8 @@ import voluptuous as vol
|
|||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components import group
|
from homeassistant.components import group
|
||||||
from homeassistant.helpers import intent
|
from homeassistant.helpers import intent
|
||||||
|
@ -22,10 +22,10 @@ from homeassistant.components.zone.zone import async_active_zone
|
|||||||
from homeassistant.config import load_yaml_config_file, async_log_exception
|
from homeassistant.config import load_yaml_config_file, async_log_exception
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import config_per_platform, discovery
|
from homeassistant.helpers import config_per_platform, discovery
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from homeassistant.helpers.typing import GPSType, ConfigType, HomeAssistantType
|
from homeassistant.helpers.typing import GPSType, ConfigType, HomeAssistantType
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant import util
|
from homeassistant import util
|
||||||
from homeassistant.util.async_ import run_coroutine_threadsafe
|
from homeassistant.util.async_ import run_coroutine_threadsafe
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
@ -96,6 +96,7 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
|||||||
vol.Optional(CONF_NEW_DEVICE_DEFAULTS,
|
vol.Optional(CONF_NEW_DEVICE_DEFAULTS,
|
||||||
default={}): NEW_DEVICE_DEFAULTS_SCHEMA
|
default={}): NEW_DEVICE_DEFAULTS_SCHEMA
|
||||||
})
|
})
|
||||||
|
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE.extend(PLATFORM_SCHEMA.schema)
|
||||||
SERVICE_SEE_PAYLOAD_SCHEMA = vol.Schema(vol.All(
|
SERVICE_SEE_PAYLOAD_SCHEMA = vol.Schema(vol.All(
|
||||||
cv.has_at_least_one_key(ATTR_MAC, ATTR_DEV_ID), {
|
cv.has_at_least_one_key(ATTR_MAC, ATTR_DEV_ID), {
|
||||||
ATTR_MAC: cv.string,
|
ATTR_MAC: cv.string,
|
||||||
|
@ -16,7 +16,8 @@ from homeassistant.const import (SERVICE_TURN_ON, SERVICE_TOGGLE,
|
|||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -9,7 +9,8 @@ import logging
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE
|
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
|||||||
vol.Optional(CONF_CONFIDENCE, default=DEFAULT_CONFIDENCE):
|
vol.Optional(CONF_CONFIDENCE, default=DEFAULT_CONFIDENCE):
|
||||||
vol.All(vol.Coerce(float), vol.Range(min=0, max=100)),
|
vol.All(vol.Coerce(float), vol.Range(min=0, max=100)),
|
||||||
})
|
})
|
||||||
|
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE.extend(PLATFORM_SCHEMA.schema)
|
||||||
|
|
||||||
SERVICE_SCAN_SCHEMA = vol.Schema({
|
SERVICE_SCAN_SCHEMA = vol.Schema({
|
||||||
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
|
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
|
||||||
|
@ -20,7 +20,8 @@ from homeassistant.const import (
|
|||||||
STATE_ON)
|
STATE_ON)
|
||||||
from homeassistant.exceptions import UnknownUser, Unauthorized
|
from homeassistant.exceptions import UnknownUser, Unauthorized
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers import intent
|
from homeassistant.helpers import intent
|
||||||
|
@ -13,7 +13,8 @@ import voluptuous as vol
|
|||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_CODE, ATTR_CODE_FORMAT, ATTR_ENTITY_ID, STATE_LOCKED, STATE_UNLOCKED,
|
ATTR_CODE, ATTR_CODE_FORMAT, ATTR_ENTITY_ID, STATE_LOCKED, STATE_UNLOCKED,
|
||||||
|
@ -30,7 +30,8 @@ from homeassistant.const import (
|
|||||||
STATE_OFF, STATE_PLAYING)
|
STATE_OFF, STATE_PLAYING)
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
|
@ -234,7 +234,7 @@ MQTT_JSON_ATTRS_SCHEMA = vol.Schema({
|
|||||||
vol.Optional(CONF_JSON_ATTRS_TOPIC): valid_subscribe_topic,
|
vol.Optional(CONF_JSON_ATTRS_TOPIC): valid_subscribe_topic,
|
||||||
})
|
})
|
||||||
|
|
||||||
MQTT_BASE_PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA_2.extend(SCHEMA_BASE)
|
MQTT_BASE_PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend(SCHEMA_BASE)
|
||||||
|
|
||||||
# Sensor type platforms subscribe to MQTT events
|
# Sensor type platforms subscribe to MQTT events
|
||||||
MQTT_RO_PLATFORM_SCHEMA = MQTT_BASE_PLATFORM_SCHEMA.extend({
|
MQTT_RO_PLATFORM_SCHEMA = MQTT_BASE_PLATFORM_SCHEMA.extend({
|
||||||
|
@ -13,7 +13,8 @@ import voluptuous as vol
|
|||||||
from homeassistant.components import camera, mqtt
|
from homeassistant.components import camera, mqtt
|
||||||
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
|
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
|
||||||
from homeassistant.components.mqtt import (
|
from homeassistant.components.mqtt import (
|
||||||
ATTR_DISCOVERY_HASH, CONF_UNIQUE_ID, MqttDiscoveryUpdate, subscription)
|
ATTR_DISCOVERY_HASH, CONF_STATE_TOPIC, CONF_UNIQUE_ID, MqttDiscoveryUpdate,
|
||||||
|
subscription)
|
||||||
from homeassistant.components.mqtt.discovery import (
|
from homeassistant.components.mqtt.discovery import (
|
||||||
MQTT_DISCOVERY_NEW, clear_discovery_hash)
|
MQTT_DISCOVERY_NEW, clear_discovery_hash)
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
@ -47,7 +48,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
async def async_discover(discovery_payload):
|
async def async_discover(discovery_payload):
|
||||||
"""Discover and add a MQTT camera."""
|
"""Discover and add a MQTT camera."""
|
||||||
try:
|
try:
|
||||||
discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH]
|
discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH)
|
||||||
|
# state_topic is implicitly set by MQTT discovery, remove it
|
||||||
|
discovery_payload.pop(CONF_STATE_TOPIC, None)
|
||||||
config = PLATFORM_SCHEMA(discovery_payload)
|
config = PLATFORM_SCHEMA(discovery_payload)
|
||||||
await _async_setup_entity(config, async_add_entities,
|
await _async_setup_entity(config, async_add_entities,
|
||||||
discovery_hash)
|
discovery_hash)
|
||||||
@ -89,6 +92,8 @@ class MqttCamera(MqttDiscoveryUpdate, Camera):
|
|||||||
|
|
||||||
async def discovery_update(self, discovery_payload):
|
async def discovery_update(self, discovery_payload):
|
||||||
"""Handle updated discovery message."""
|
"""Handle updated discovery message."""
|
||||||
|
# state_topic is implicitly set by MQTT discovery, remove it
|
||||||
|
discovery_payload.pop(CONF_STATE_TOPIC, None)
|
||||||
config = PLATFORM_SCHEMA(discovery_payload)
|
config = PLATFORM_SCHEMA(discovery_payload)
|
||||||
self._config = config
|
self._config = config
|
||||||
await self._subscribe_topics()
|
await self._subscribe_topics()
|
||||||
|
@ -17,9 +17,9 @@ from homeassistant.components.climate import (
|
|||||||
SUPPORT_SWING_MODE, SUPPORT_TARGET_TEMPERATURE, ClimateDevice)
|
SUPPORT_SWING_MODE, SUPPORT_TARGET_TEMPERATURE, ClimateDevice)
|
||||||
from homeassistant.components.fan import SPEED_HIGH, SPEED_LOW, SPEED_MEDIUM
|
from homeassistant.components.fan import SPEED_HIGH, SPEED_LOW, SPEED_MEDIUM
|
||||||
from homeassistant.components.mqtt import (
|
from homeassistant.components.mqtt import (
|
||||||
ATTR_DISCOVERY_HASH, CONF_QOS, CONF_RETAIN, CONF_UNIQUE_ID,
|
ATTR_DISCOVERY_HASH, CONF_QOS, CONF_RETAIN, CONF_STATE_TOPIC,
|
||||||
MQTT_BASE_PLATFORM_SCHEMA, MqttAttributes, MqttAvailability,
|
CONF_UNIQUE_ID, MQTT_BASE_PLATFORM_SCHEMA, MqttAttributes,
|
||||||
MqttDiscoveryUpdate, MqttEntityDeviceInfo, subscription)
|
MqttAvailability, MqttDiscoveryUpdate, MqttEntityDeviceInfo, subscription)
|
||||||
from homeassistant.components.mqtt.discovery import (
|
from homeassistant.components.mqtt.discovery import (
|
||||||
MQTT_DISCOVERY_NEW, clear_discovery_hash)
|
MQTT_DISCOVERY_NEW, clear_discovery_hash)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -156,7 +156,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
async def async_discover(discovery_payload):
|
async def async_discover(discovery_payload):
|
||||||
"""Discover and add a MQTT climate device."""
|
"""Discover and add a MQTT climate device."""
|
||||||
try:
|
try:
|
||||||
discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH]
|
discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH)
|
||||||
|
# state_topic is implicitly set by MQTT discovery, remove it
|
||||||
|
discovery_payload.pop(CONF_STATE_TOPIC, None)
|
||||||
config = PLATFORM_SCHEMA(discovery_payload)
|
config = PLATFORM_SCHEMA(discovery_payload)
|
||||||
await _async_setup_entity(hass, config, async_add_entities,
|
await _async_setup_entity(hass, config, async_add_entities,
|
||||||
config_entry, discovery_hash)
|
config_entry, discovery_hash)
|
||||||
@ -217,6 +219,8 @@ class MqttClimate(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
|
|||||||
|
|
||||||
async def discovery_update(self, discovery_payload):
|
async def discovery_update(self, discovery_payload):
|
||||||
"""Handle updated discovery message."""
|
"""Handle updated discovery message."""
|
||||||
|
# state_topic is implicitly set by MQTT discovery, remove it
|
||||||
|
discovery_payload.pop(CONF_STATE_TOPIC, None)
|
||||||
config = PLATFORM_SCHEMA(discovery_payload)
|
config = PLATFORM_SCHEMA(discovery_payload)
|
||||||
self._config = config
|
self._config = config
|
||||||
self._setup_from_config(config)
|
self._setup_from_config(config)
|
||||||
|
@ -18,7 +18,8 @@ from homeassistant.const import (
|
|||||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE,
|
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE,
|
||||||
ATTR_ENTITY_ID)
|
ATTR_ENTITY_ID)
|
||||||
from homeassistant.components import group
|
from homeassistant.components import group
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE,
|
DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE,
|
||||||
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_PRESSURE)
|
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_PRESSURE)
|
||||||
|
@ -38,12 +38,11 @@ DEFAULT_TOPIC = 'room_presence'
|
|||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_DEVICE_ID): cv.string,
|
vol.Required(CONF_DEVICE_ID): cv.string,
|
||||||
vol.Required(CONF_STATE_TOPIC, default=DEFAULT_TOPIC): cv.string,
|
|
||||||
vol.Required(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
|
vol.Required(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
|
||||||
vol.Optional(CONF_AWAY_TIMEOUT,
|
vol.Optional(CONF_AWAY_TIMEOUT,
|
||||||
default=DEFAULT_AWAY_TIMEOUT): cv.positive_int,
|
default=DEFAULT_AWAY_TIMEOUT): cv.positive_int,
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string
|
||||||
})
|
}).extend(mqtt.MQTT_RO_PLATFORM_SCHEMA.schema)
|
||||||
|
|
||||||
MQTT_PAYLOAD = vol.Schema(vol.All(json.loads, vol.Schema({
|
MQTT_PAYLOAD = vol.Schema(vol.All(json.loads, vol.Schema({
|
||||||
vol.Required(ATTR_ID): cv.string,
|
vol.Required(ATTR_ID): cv.string,
|
||||||
|
@ -12,7 +12,8 @@ import voluptuous as vol
|
|||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE,
|
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE,
|
||||||
|
@ -68,6 +68,7 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
|||||||
vol.All(vol.Coerce(int), vol.Range(min=60, max=57600)),
|
vol.All(vol.Coerce(int), vol.Range(min=60, max=57600)),
|
||||||
vol.Optional(CONF_BASE_URL): cv.string,
|
vol.Optional(CONF_BASE_URL): cv.string,
|
||||||
})
|
})
|
||||||
|
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE.extend(PLATFORM_SCHEMA.schema)
|
||||||
|
|
||||||
SCHEMA_SERVICE_SAY = vol.Schema({
|
SCHEMA_SERVICE_SAY = vol.Schema({
|
||||||
vol.Required(ATTR_MESSAGE): cv.string,
|
vol.Required(ATTR_MESSAGE): cv.string,
|
||||||
|
@ -16,7 +16,8 @@ from homeassistant.const import (
|
|||||||
SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_ON, STATE_PAUSED, STATE_IDLE)
|
SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_ON, STATE_PAUSED, STATE_IDLE)
|
||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.entity import (ToggleEntity, Entity)
|
from homeassistant.helpers.entity import (ToggleEntity, Entity)
|
||||||
from homeassistant.helpers.icon import icon_for_battery_level
|
from homeassistant.helpers.icon import icon_for_battery_level
|
||||||
|
@ -14,7 +14,8 @@ from homeassistant.helpers.temperature import display_temp as show_temp
|
|||||||
from homeassistant.util.temperature import convert as convert_temperature
|
from homeassistant.util.temperature import convert as convert_temperature
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID, ATTR_TEMPERATURE, SERVICE_TURN_ON, SERVICE_TURN_OFF,
|
ATTR_ENTITY_ID, ATTR_TEMPERATURE, SERVICE_TURN_ON, SERVICE_TURN_OFF,
|
||||||
|
@ -10,7 +10,8 @@ import logging
|
|||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.temperature import display_temp as show_temp
|
from homeassistant.helpers.temperature import display_temp as show_temp
|
||||||
from homeassistant.const import PRECISION_WHOLE, PRECISION_TENTHS, TEMP_CELSIUS
|
from homeassistant.const import PRECISION_WHOLE, PRECISION_TENTHS, TEMP_CELSIUS
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -556,16 +556,9 @@ PLATFORM_SCHEMA = vol.Schema({
|
|||||||
vol.Required(CONF_PLATFORM): string,
|
vol.Required(CONF_PLATFORM): string,
|
||||||
vol.Optional(CONF_ENTITY_NAMESPACE): string,
|
vol.Optional(CONF_ENTITY_NAMESPACE): string,
|
||||||
vol.Optional(CONF_SCAN_INTERVAL): time_period
|
vol.Optional(CONF_SCAN_INTERVAL): time_period
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
|
||||||
|
|
||||||
# This will replace PLATFORM_SCHEMA once all base components are updated
|
|
||||||
PLATFORM_SCHEMA_2 = vol.Schema({
|
|
||||||
vol.Required(CONF_PLATFORM): string,
|
|
||||||
vol.Optional(CONF_ENTITY_NAMESPACE): string,
|
|
||||||
vol.Optional(CONF_SCAN_INTERVAL): time_period
|
|
||||||
})
|
})
|
||||||
|
|
||||||
PLATFORM_SCHEMA_BASE = PLATFORM_SCHEMA_2.extend({
|
PLATFORM_SCHEMA_BASE = PLATFORM_SCHEMA.extend({
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
EVENT_SCHEMA = vol.Schema({
|
EVENT_SCHEMA = vol.Schema({
|
||||||
|
@ -99,7 +99,6 @@ class TestRestBinarySensorSetup(unittest.TestCase):
|
|||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
'value_template': '{{ value_json.key }}',
|
'value_template': '{{ value_json.key }}',
|
||||||
'name': 'foo',
|
'name': 'foo',
|
||||||
'unit_of_measurement': 'MB',
|
|
||||||
'verify_ssl': 'true',
|
'verify_ssl': 'true',
|
||||||
'authentication': 'basic',
|
'authentication': 'basic',
|
||||||
'username': 'my username',
|
'username': 'my username',
|
||||||
@ -122,7 +121,6 @@ class TestRestBinarySensorSetup(unittest.TestCase):
|
|||||||
'value_template': '{{ value_json.key }}',
|
'value_template': '{{ value_json.key }}',
|
||||||
'payload': '{ "device": "toaster"}',
|
'payload': '{ "device": "toaster"}',
|
||||||
'name': 'foo',
|
'name': 'foo',
|
||||||
'unit_of_measurement': 'MB',
|
|
||||||
'verify_ssl': 'true',
|
'verify_ssl': 'true',
|
||||||
'authentication': 'basic',
|
'authentication': 'basic',
|
||||||
'username': 'my username',
|
'username': 'my username',
|
||||||
|
@ -416,33 +416,6 @@ async def test_nogroup_device_id(hass, monkeypatch):
|
|||||||
assert hass.states.get(DOMAIN + '.test').state == STATE_OPEN
|
assert hass.states.get(DOMAIN + '.test').state == STATE_OPEN
|
||||||
|
|
||||||
|
|
||||||
async def test_disable_automatic_add(hass, monkeypatch):
|
|
||||||
"""If disabled new devices should not be automatically added."""
|
|
||||||
config = {
|
|
||||||
'rflink': {
|
|
||||||
'port': '/dev/ttyABC0',
|
|
||||||
},
|
|
||||||
DOMAIN: {
|
|
||||||
'platform': 'rflink',
|
|
||||||
'automatic_add': False,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
# setup mocking rflink module
|
|
||||||
event_callback, _, _, _ = await mock_rflink(
|
|
||||||
hass, config, DOMAIN, monkeypatch)
|
|
||||||
|
|
||||||
# test event for new unconfigured sensor
|
|
||||||
event_callback({
|
|
||||||
'id': 'protocol_0_0',
|
|
||||||
'command': 'down',
|
|
||||||
})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# make sure new device is not added
|
|
||||||
assert not hass.states.get(DOMAIN + '.protocol_0_0')
|
|
||||||
|
|
||||||
|
|
||||||
async def test_restore_state(hass, monkeypatch):
|
async def test_restore_state(hass, monkeypatch):
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
config = {
|
config = {
|
||||||
|
@ -679,7 +679,8 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
|||||||
climate.DOMAIN: {
|
climate.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'state_topic': 'test-topic',
|
'power_state_topic': 'test-topic',
|
||||||
|
'power_command_topic': 'test_topic',
|
||||||
'json_attributes_topic': 'attr-topic'
|
'json_attributes_topic': 'attr-topic'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -697,7 +698,8 @@ async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
|||||||
climate.DOMAIN: {
|
climate.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'state_topic': 'test-topic',
|
'power_state_topic': 'test-topic',
|
||||||
|
'power_command_topic': 'test_topic',
|
||||||
'json_attributes_topic': 'attr-topic'
|
'json_attributes_topic': 'attr-topic'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -716,7 +718,8 @@ async def test_update_with_json_attrs_bad_JSON(hass, mqtt_mock, caplog):
|
|||||||
climate.DOMAIN: {
|
climate.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'state_topic': 'test-topic',
|
'power_state_topic': 'test-topic',
|
||||||
|
'power_command_topic': 'test_topic',
|
||||||
'json_attributes_topic': 'attr-topic'
|
'json_attributes_topic': 'attr-topic'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -735,12 +738,14 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
|||||||
await async_start(hass, 'homeassistant', {}, entry)
|
await async_start(hass, 'homeassistant', {}, entry)
|
||||||
data1 = (
|
data1 = (
|
||||||
'{ "name": "Beer",'
|
'{ "name": "Beer",'
|
||||||
' "command_topic": "test_topic",'
|
' "power_state_topic": "test-topic",'
|
||||||
|
' "power_command_topic": "test_topic",'
|
||||||
' "json_attributes_topic": "attr-topic1" }'
|
' "json_attributes_topic": "attr-topic1" }'
|
||||||
)
|
)
|
||||||
data2 = (
|
data2 = (
|
||||||
'{ "name": "Beer",'
|
'{ "name": "Beer",'
|
||||||
' "command_topic": "test_topic",'
|
' "power_state_topic": "test-topic",'
|
||||||
|
' "power_command_topic": "test_topic",'
|
||||||
' "json_attributes_topic": "attr-topic2" }'
|
' "json_attributes_topic": "attr-topic2" }'
|
||||||
)
|
)
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/climate/bla/config',
|
async_fire_mqtt_message(hass, 'homeassistant/climate/bla/config',
|
||||||
@ -780,14 +785,14 @@ async def test_unique_id(hass):
|
|||||||
climate.DOMAIN: [{
|
climate.DOMAIN: [{
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'Test 1',
|
'name': 'Test 1',
|
||||||
'status_topic': 'test-topic',
|
'power_state_topic': 'test-topic',
|
||||||
'command_topic': 'test_topic',
|
'power_command_topic': 'test_topic',
|
||||||
'unique_id': 'TOTALLY_UNIQUE'
|
'unique_id': 'TOTALLY_UNIQUE'
|
||||||
}, {
|
}, {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'Test 2',
|
'name': 'Test 2',
|
||||||
'status_topic': 'test-topic',
|
'power_state_topic': 'test-topic',
|
||||||
'command_topic': 'test_topic',
|
'power_command_topic': 'test_topic',
|
||||||
'unique_id': 'TOTALLY_UNIQUE'
|
'unique_id': 'TOTALLY_UNIQUE'
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
@ -891,8 +896,6 @@ async def test_entity_device_info_with_identifier(hass, mqtt_mock):
|
|||||||
data = json.dumps({
|
data = json.dumps({
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'Test 1',
|
'name': 'Test 1',
|
||||||
'state_topic': 'test-topic',
|
|
||||||
'command_topic': 'test-topic',
|
|
||||||
'device': {
|
'device': {
|
||||||
'identifiers': ['helloworld'],
|
'identifiers': ['helloworld'],
|
||||||
'connections': [
|
'connections': [
|
||||||
@ -930,8 +933,8 @@ async def test_entity_device_info_update(hass, mqtt_mock):
|
|||||||
config = {
|
config = {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'Test 1',
|
'name': 'Test 1',
|
||||||
'state_topic': 'test-topic',
|
'power_state_topic': 'test-topic',
|
||||||
'command_topic': 'test-command-topic',
|
'power_command_topic': 'test-command-topic',
|
||||||
'device': {
|
'device': {
|
||||||
'identifiers': ['helloworld'],
|
'identifiers': ['helloworld'],
|
||||||
'connections': [
|
'connections': [
|
||||||
|
@ -59,7 +59,6 @@ class TestFilterSensor(unittest.TestCase):
|
|||||||
'platform': 'filter',
|
'platform': 'filter',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'entity_id': 'sensor.test_monitored',
|
'entity_id': 'sensor.test_monitored',
|
||||||
'history_period': '00:05',
|
|
||||||
'filters': [{
|
'filters': [{
|
||||||
'filter': 'outlier',
|
'filter': 'outlier',
|
||||||
'window_size': 10,
|
'window_size': 10,
|
||||||
|
@ -110,7 +110,7 @@ def test_platform_config():
|
|||||||
{'platform': 'mqtt', 'beer': 'yes'},
|
{'platform': 'mqtt', 'beer': 'yes'},
|
||||||
)
|
)
|
||||||
for value in options:
|
for value in options:
|
||||||
cv.PLATFORM_SCHEMA(value)
|
cv.PLATFORM_SCHEMA_BASE(value)
|
||||||
|
|
||||||
|
|
||||||
def test_ensure_list():
|
def test_ensure_list():
|
||||||
|
@ -15,7 +15,7 @@ import homeassistant.config as config_util
|
|||||||
from homeassistant import setup, loader
|
from homeassistant import setup, loader
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.helpers.config_validation import (
|
from homeassistant.helpers.config_validation import (
|
||||||
PLATFORM_SCHEMA_2 as PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
|
|
||||||
from tests.common import \
|
from tests.common import \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user