1 """Support for X10 switch over Mochad."""
3 from __future__
import annotations
8 from pymochad
import controller, device
9 from pymochad.exceptions
import MochadException
10 import voluptuous
as vol
19 from .
import CONF_COMM_TYPE, DOMAIN, REQ_LOCK, MochadCtrl
21 _LOGGER = logging.getLogger(__name__)
24 PLATFORM_SCHEMA = vol.Schema(
26 vol.Required(CONF_PLATFORM): DOMAIN,
29 vol.Optional(CONF_NAME): cv.string,
30 vol.Required(CONF_ADDRESS): cv.x10_address,
31 vol.Optional(CONF_COMM_TYPE): cv.string,
41 add_entities: AddEntitiesCallback,
42 discovery_info: DiscoveryInfoType |
None =
None,
44 """Set up X10 switches over a mochad controller."""
45 mochad_controller: MochadCtrl = hass.data[DOMAIN]
46 devs: list[dict[str, str]] = config[CONF_DEVICES]
51 """Representation of a X10 switch over Mochad."""
54 self, hass: HomeAssistant, ctrl: controller.PyMochad, dev: dict[str, str]
56 """Initialize a Mochad Switch Device."""
59 self._address: str = dev[CONF_ADDRESS]
60 self._attr_name: str = dev.get(CONF_NAME, f
"x10_switch_dev_{self._address}")
61 self.
_comm_type_comm_type: str = dev.get(CONF_COMM_TYPE,
"pl")
62 self.
switchswitch = device.Device(ctrl, self._address, comm_type=self.
_comm_type_comm_type)
71 """Turn the switch on."""
78 self.
switchswitch.send_cmd(
"on")
83 except (MochadException, OSError)
as exc:
84 _LOGGER.error(
"Error with mochad communication: %s", exc)
87 """Turn the switch off."""
94 self.
switchswitch.send_cmd(
"off")
99 except (MochadException, OSError)
as exc:
100 _LOGGER.error(
"Error with mochad communication: %s", exc)
103 """Get the status of the switch from mochad."""
106 return status ==
"on"
None turn_on(self, **Any kwargs)
None __init__(self, HomeAssistant hass, controller.PyMochad ctrl, dict[str, str] dev)
bool _get_device_status(self)
None turn_off(self, **Any kwargs)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
def get_status(hass, host, port)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)