+ def _do_request(self, state):
+ state_val = 1 if state else 0
+ try:
+ logger.info("Setting SpaceAPI to %d" % state_val)
+ url = "http://spaceapi.hacksaar.de/status.php?action=update&key=%s&status=%d" % (spaceApiKey, state_val)
+ response = urllib.request.urlopen(url, timeout=5.0)
+ responseText = response.read().decode('utf-8').strip()
+ if response.getcode() == 200 and responseText == "UpdateSuccessful": return True
+ logger.error("SpaceAPI returned unexpected code %d, content %s" % (response.getcode(), responseText))
+ return False
+ except urllib.request.URLError as e:
+ logger.error("SpaceAPI update returned error: %s" % str(e))
+ return False
+