def setup(hass, config): """Set up the Mopar component.""" import motorparts conf = config[DOMAIN] cookie = hass.config.path(COOKIE_FILE) try: session = motorparts.get_session( conf[CONF_USERNAME], conf[CONF_PASSWORD], conf[CONF_PIN], cookie_path=cookie ) except motorparts.MoparError: _LOGGER.error("Failed to login") return False data = hass.data[DOMAIN] = MoparData(hass, session) data.update(now=None) track_time_interval(hass, data.update, conf[CONF_SCAN_INTERVAL]) def handle_horn(call): """Enable the horn on the Mopar vehicle.""" data.actuate("horn", call.data[ATTR_VEHICLE_INDEX]) hass.services.register( DOMAIN, SERVICE_HORN, handle_horn, schema=SERVICE_HORN_SCHEMA ) for platform in SUPPORTED_PLATFORMS: load_platform(hass, platform, DOMAIN, {}, config) return True
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Mopar platform.""" import motorparts cookie = hass.config.path(COOKIE_FILE) try: session = motorparts.get_session(config.get(CONF_USERNAME), config.get(CONF_PASSWORD), config.get(CONF_PIN), cookie_path=cookie) except motorparts.MoparError: _LOGGER.error("failed to login") return False def _handle_service(service): """Handle service call.""" index = service.data.get(ATTR_VEHICLE_INDEX) command = service.data.get(ATTR_COMMAND) try: motorparts.remote_command(session, command, index) except motorparts.MoparError as error: _LOGGER.error(str(error)) hass.services.register(DOMAIN, SERVICE_REMOTE_COMMAND, _handle_service, schema=REMOTE_COMMAND_SCHEMA) data = MoparData(session) add_devices( [MoparSensor(data, index) for index, _ in enumerate(data.vehicles)], True) return True
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Mopar platform.""" import motorparts cookie = hass.config.path(COOKIE_FILE) try: session = motorparts.get_session( config.get(CONF_USERNAME), config.get(CONF_PASSWORD), config.get(CONF_PIN), cookie_path=cookie) except motorparts.MoparError: _LOGGER.error("Failed to login") return def _handle_service(service): """Handle service call.""" index = service.data.get(ATTR_VEHICLE_INDEX) command = service.data.get(ATTR_COMMAND) try: motorparts.remote_command(session, command, index) except motorparts.MoparError as error: _LOGGER.error(str(error)) hass.services.register(DOMAIN, SERVICE_REMOTE_COMMAND, _handle_service, schema=REMOTE_COMMAND_SCHEMA) data = MoparData(session) add_devices([MoparSensor(data, index) for index, _ in enumerate(data.vehicles)], True)
def setup(hass, config): """Set up the Mopar component.""" import motorparts conf = config[DOMAIN] cookie = hass.config.path(COOKIE_FILE) try: session = motorparts.get_session( conf[CONF_USERNAME], conf[CONF_PASSWORD], conf[CONF_PIN], cookie_path=cookie ) except motorparts.MoparError: _LOGGER.error("Failed to login") return False data = hass.data[DOMAIN] = MoparData(hass, session) data.update(now=None) track_time_interval( hass, data.update, conf[CONF_SCAN_INTERVAL] ) def handle_horn(call): """Enable the horn on the Mopar vehicle.""" data.actuate('horn', call.data[ATTR_VEHICLE_INDEX]) hass.services.register( DOMAIN, SERVICE_HORN, handle_horn, schema=SERVICE_HORN_SCHEMA ) for platform in SUPPORTED_PLATFORMS: load_platform(hass, platform, DOMAIN, {}, config) return True