1 """Support for CM15A/CM19A X10 Controller using mochad daemon."""
6 from pymochad
import controller, exceptions
7 import voluptuous
as vol
12 EVENT_HOMEASSISTANT_START,
13 EVENT_HOMEASSISTANT_STOP,
19 _LOGGER = logging.getLogger(__name__)
21 CONF_COMM_TYPE =
"comm_type"
25 REQ_LOCK = threading.Lock()
27 CONFIG_SCHEMA = vol.Schema(
31 vol.Optional(CONF_HOST, default=
"localhost"): cv.string,
32 vol.Optional(CONF_PORT, default=1099): cv.port,
36 extra=vol.ALLOW_EXTRA,
40 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
41 """Set up the mochad component."""
43 host = conf.get(CONF_HOST)
44 port = conf.get(CONF_PORT)
48 except exceptions.ConfigurationError:
49 _LOGGER.exception(
"Unexpected exception")
52 def stop_mochad(event):
53 """Stop the Mochad service."""
54 mochad_controller.disconnect()
56 def start_mochad(event):
57 """Start the Mochad service."""
58 hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_mochad)
60 hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_mochad)
61 hass.data[DOMAIN] = mochad_controller
67 """Mochad controller."""
70 """Initialize a PyMochad controller."""
75 self.
ctrlctrl = controller.PyMochad(server=self.
_host_host, port=self.
_port_port)
79 """Return the server where mochad is running."""
80 return self.
_host_host
84 """Return the port mochad is running on."""
85 return self.
_port_port
88 """Close the connection to the mochad socket."""
89 self.
ctrlctrl.socket.close()
def __init__(self, host, port)
bool setup(HomeAssistant hass, ConfigType config)