1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00
ha-core/homeassistant/components/pilight/switch.py
epenet 8756fa28e2
Add setup type hints [o-q] (#63465)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2022-01-05 16:29:21 +01:00

38 lines
1.2 KiB
Python

"""Support for switching devices via Pilight to on and off."""
from __future__ import annotations
import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
from homeassistant.const import CONF_SWITCHES
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 .base_class import SWITCHES_SCHEMA, PilightBaseDevice
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Required(CONF_SWITCHES): vol.Schema({cv.string: SWITCHES_SCHEMA})}
)
def setup_platform(
hass: HomeAssistant,
config: ConfigType,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Pilight platform."""
switches = config[CONF_SWITCHES]
devices = []
for dev_name, dev_config in switches.items():
devices.append(PilightSwitch(hass, dev_name, dev_config))
add_entities(devices)
class PilightSwitch(PilightBaseDevice, SwitchEntity):
"""Representation of a Pilight switch."""