def set_timer(self, time_on, time_off, time_now=None): """ Sets new timer :param int time_on: time when to turn lights on. In seconds after midnight. To disable use -1. :param int time_off: time when to turn lights off. In seconds after midnight. To disable use -1. :param time_now: current time in seconds after midnight. Determined automatically if not set. :type time_now: int or None :raises ApplicationError: on application error :rtype: None """ assert isinstance(time_on, int) assert time_on >= -1 assert isinstance(time_off, int) assert time_off >= -1 if time_now is None: time_now = xled.util.seconds_after_midnight() log.debug("Setting time now to %s", time_now) json_payload = { "time_on": time_on, "time_off": time_off, "time_now": time_now } url = urljoin(self.base_url, "timer") response = self.session.post(url, json=json_payload) app_response = ApplicationResponse(response) required_keys = [u"code"] assert all(key in app_response.keys() for key in required_keys)
def network_scan(self): """ Initiate WiFi network scan :raises ApplicationError: on application error :rtype: None """ url = urljoin(self.base_url, "network/scan") response = self.session.get(url) app_response = ApplicationResponse(response) assert list(app_response.keys()) == [u"code"]
def get_brightness(self): """ Gets current brightness level and if dimming is applied :raises ApplicationError: on application error :rtype: :class:`~xled.response.ApplicationResponse` """ url = urljoin(self.base_url, "led/out/brightness") response = self.session.get(url) app_response = ApplicationResponse(response) assert sorted(app_response.keys()) == [u"code", u"mode", u"value"] return app_response
def set_network_mode_ap(self): """ Sets network mode to Access Point :raises ApplicationError: on application error :rtype: None """ json_payload = {"mode": 2} url = urljoin(self.base_url, "network/status") response = self.session.post(url, json=json_payload) app_response = ApplicationResponse(response) assert list(app_response.keys()) == [u"code"]
def set_mode(self, mode): """ Sets new LED operation mode. :param str mode: Mode to set. One of 'movie', 'demo', 'off'. :raises ApplicationError: on application error :rtype: None """ assert mode in ("movie", "demo", "off") json_payload = {"mode": mode} url = urljoin(self.base_url, "led/mode") response = self.session.post(url, json=json_payload) app_response = ApplicationResponse(response) assert list(app_response.keys()) == [u"code"]
def set_device_name(self, name): """ Sets new device name :param str name: new device name :raises ApplicationError: on application error :rtype: None """ assert len(name) <= 32 json_payload = {"name": name} url = urljoin(self.base_url, "device_name") response = self.session.post(url, json=json_payload) app_response = ApplicationResponse(response) assert list(app_response.keys()) == [u"code"]
def get_device_name(self): """ Gets device name. .. seealso:: :py:meth:`set_device_name()` :raises ApplicationError: on application error :return: current device name. :rtype: :class:`~xled.response.ApplicationResponse` """ url = urljoin(self.base_url, "device_name") response = self.session.get(url) app_response = ApplicationResponse(response) assert sorted(app_response.keys()) == [u"code", u"name"] return app_response
def get_timer(self): """ Gets current timer :type time_now: int or None :raises ApplicationError: on application error :return: {time_on, time_off, time_now}. See :py:meth:`set_timer()` for explanation of return values. :rtype: :class:`~xled.response.ApplicationResponse` """ url = urljoin(self.base_url, "timer") response = self.session.get(url) app_response = ApplicationResponse(response) required_keys = [u"time_now", u"time_off", u"time_on", u"code"] assert all(key in app_response.keys() for key in required_keys) return app_response
def get_mode(self): """ Gets current LED operation mode. .. seealso:: :py:meth:`set_mode()` to set modes. :raises ApplicationError: on application error :return: current LED operation mode. See :py:meth:`set_mode()` for possible return values. :rtype: :class:`~xled.response.ApplicationResponse` """ url = urljoin(self.base_url, "led/mode") response = self.session.get(url) app_response = ApplicationResponse(response) assert sorted(app_response.keys()) == [u"code", u"mode"] return app_response
def set_brightness(self, brightness=None, enabled=True): """ Sets new brightness or enable/disable brightness dimming :param brightness: new brightness in range of 0..255 or None if no change is requested :param bool enabled: set to False if the dimming should not be applied :raises ApplicationError: on application error :rtype: :class:`~xled.response.ApplicationResponse` """ assert brightness in range(0, 256) or brightness is None if enabled: json_payload = {"mode": "enabled", "type": "A"} else: json_payload = {"mode": "disabled"} if brightness is not None: json_payload["value"] = brightness url = urljoin(self.base_url, "led/out/brightness") response = self.session.post(url, json=json_payload) app_response = ApplicationResponse(response) assert list(app_response.keys()) == [u"code"] return app_response
def set_network_mode_station(self, ssid, password): """ Sets network mode to Access Point :param str ssid: SSID if the access point to connect to :param str password: password to use :raises ApplicationError: on application error :rtype: None """ assert self.hw_address encpassword = encrypt_wifi_password(password, self.hw_address) json_payload = { "mode": 1, "station": { "dhcp": 1, "ssid": ssid, "encpassword": encpassword }, } url = urljoin(self.base_url, "network/status") response = self.session.post(url, json=json_payload) app_response = ApplicationResponse(response) assert list(app_response.keys()) == [u"code"]