def test_get_services(self): """Test Python API get_services.""" local_services = hass.services.services for serv_domain in remote.get_services(master_api): local = local_services.pop(serv_domain["domain"]) self.assertEqual(local, serv_domain["services"]) self.assertEqual({}, remote.get_services(broken_api))
def get_services(api, domain): """Get a list of available services.""" import homeassistant.remote as remote services = remote.get_services(api) for service in services: if service['domain'] != domain: continue return list(service['services'])
def test_get_services(self): """ Test Python API get_services. """ local_services = self.hass.services.services for serv_domain in remote.get_services(self.api): local = local_services.pop(serv_domain["domain"]) self.assertEqual(serv_domain["services"], local)
def cli(ctx, domain, service, data): """Query and call services.""" import homeassistant.remote as remote # If no service is given, we want to either print all services # from the given domain, or everything if no domain is given if service is None and data is None: for serv in remote.get_services(ctx.api): if domain is not None and domain != serv['domain']: continue print_service(ctx, serv) return if data is not None: data = ast.literal_eval(data) ctx.log("Calling %s.%s with data %s", domain, service, data) res = remote.call_service(ctx.api, domain, service, data) ctx.log("Return value: %s", res)
def cli(ctx, entry): """List various entries of an instance.""" import homeassistant.remote as remote ctx.log('Available %s', entry) if entry == 'services': services = remote.get_services(ctx.api) for service in services: ctx.log(json_output(service['services'])) if entry == 'events': events = remote.get_event_listeners(ctx.api) for event in events: ctx.log(event) if entry == 'entities': entities = remote.get_states(ctx.api) for entity in entities: ctx.log(entity) ctx.vlog('Details of %s, Created: %s', ctx.host, timestamp())
def refresh_services (): services = remote.get_services(api) for service in services: print(service['domain'])
ha_ssl = config['ha_ssl'] ha_alarm_entity = config['ha_alarm_entity'] ha_alarm_code = config['ha_alarm_code'] bot_token = config['bot_token'] allowed_chat_ids = config['allowed_chat_ids'] fav_entities = config['fav_entities'] fav_entities = fav_entities.split() show_maps = config['show_maps'] # instance the API connection to HASS api = remote.API(ha_url, ha_key, ha_port, ha_ssl) print(remote.validate_api(api)) # this prints out all the HASS services - mostly here for testing atm print('-- Available Domains/Services:') services = remote.get_services(api) for service in services: print(service['domain']) print(service['services']) # instance the Telegram bot bot = telepot.Bot(bot_token) # calls the HASS API to get the state of an entity # need to change this so you can pass in entity type so we can get the right attributes for display def get_state (entity_id, readable): print(entity_id) entity = remote.get_state(api, entity_id) if (readable == 'true'): state = format('{} is {}.'.format(entity.attributes['friendly_name'], entity.state)) else:
def get_services(self): pprint(remote.get_services(api))
def services_counter(api): """Count all available services.""" import homeassistant.remote as remote return len(remote.get_services(api))
def test_get_services(self): """ Test Python API get_services. """ self.assertEqual( remote.get_services(self.api), self.hass.services.services)
def _services(self): return remote.get_services(self.api)