1 """Support for X10 lights."""
3 from __future__
import annotations
6 from subprocess
import STDOUT, CalledProcessError, check_output
9 import voluptuous
as vol
13 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
23 _LOGGER = logging.getLogger(__name__)
25 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
27 vol.Required(CONF_DEVICES): vol.All(
29 [{vol.Required(CONF_ID): cv.string, vol.Required(CONF_NAME): cv.string}],
36 """Execute X10 command and check output."""
37 return check_output([
"heyu", *command.split(
" ")], stderr=STDOUT)
41 """Get on/off status for given unit."""
42 output = check_output([
"heyu",
"onstate", code])
43 return int(output.decode(
"utf-8")[0])
49 add_entities: AddEntitiesCallback,
50 discovery_info: DiscoveryInfoType |
None =
None,
52 """Set up the x10 Light platform."""
56 except CalledProcessError
as err:
57 _LOGGER.warning(
"Assuming that the device is CM17A: %s", err.output)
64 """Representation of an X10 Light."""
66 _attr_color_mode = ColorMode.BRIGHTNESS
67 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
70 """Initialize an X10 Light."""
72 self.
_id_id = light[
"id"]
79 """Return the display name of this light."""
80 return self.
_name_name
84 """Return the brightness of the light."""
89 """Return true if light is on."""
93 """Instruct the light to turn on."""
98 self.
_brightness_brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
102 """Instruct the light to turn off."""
110 """Fetch update state."""
None turn_on(self, **Any kwargs)
def __init__(self, light, is_cm11a)
None turn_off(self, **Any kwargs)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
def get_unit_status(code)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)