def create(cls, **kwargs): path = 'commands' response = post(path, kwargs) if WiaResource.is_success(response): return cls(**response.json()) else: return WiaResource.error_response(response)
def create(cls, **kwargs): path = 'devices' response = post(path, kwargs) if WiaResource.is_success(response): return cls(**WiaResource.json_converter(response)) else: return WiaResource.error_response(response)
def create(cls, **kwargs): """ Creates a Space in Wia for devices :param kwargs: :return: Returns a newly created space """ path = 'spaces' response = post(path, kwargs) if WiaResource.is_success(response): return cls(**response.json()) else: return WiaResource.error_response(response)
def publish(cls, **kwargs): path = 'locations' if Wia().Stream.connected and Wia().client_id is not None: topic = 'devices/' + Wia().client_id + '/' + path Wia().Stream.publish(topic=topic, **kwargs) return cls() else: response = post(path, kwargs) if WiaResource.is_success(response): return cls(**response.json()) else: return WiaResource.error_response(response)
def run(cls, **kwargs): if Wia().Stream.connected and Wia().client_id is not None: command = 'devices/' + Wia().client_id + '/commands/' + ( kwargs['slug'] or kwargs['name']) + '/run' Wia().Stream.run(command=command) return cls() else: response = post('commands/run', kwargs) if WiaResource.is_success(response): return cls(**response.json()) else: return WiaResource.error_response(response)
def publish(cls, **kwargs): path = 'events' if not ('file' in kwargs) and Wia().Stream.connected and Wia( ).client_id is not None: topic = 'devices/' + Wia( ).client_id + '/' + path + '/' + kwargs['name'] Wia().Stream.publish(topic=topic, **kwargs) return cls() else: response = post(path, kwargs) if WiaResource.is_success(response): return cls(**WiaResource.json_converter(response)) else: return WiaResource.error_response(response)
def create(cls, kwargs): response = post('auth/token', kwargs) if WiaResource.is_success(response): return cls(**response.json()) else: return WiaResource.error_response(response)