diff --git a/.gitignore b/.gitignore index 44214b6..19591bf 100644 --- a/.gitignore +++ b/.gitignore @@ -147,4 +147,7 @@ dmypy.json .pytype/ test-reports/ -test.py \ No newline at end of file +test.py + +# pipfile +Pipfile.lock diff --git a/Pipfile b/Pipfile index 90617ca..f293ffe 100644 --- a/Pipfile +++ b/Pipfile @@ -1,12 +1,21 @@ [[source]] -name = "pypi" url = "https://pypi.org/simple" verify_ssl = true - -[dev-packages] +name = "pypi" [packages] -requests = "*" +requests = "==2.23.0" + +[dev-packages] +black = "==19.10b0" +flake8 = "==3.7.9" +isort = "==4.3.21" +pre-commit = "==2.1.1" +ptvsd = "==4.3.2" +pycodestyle = "==2.5.0" +pyflakes = "==2.1.1" +pylint = "==2.4.4" +requests = "==2.23.0" [requires] -python_version = "3.6" +python_version = "3.9" diff --git a/Pipfile.lock b/Pipfile.lock deleted file mode 100644 index 066443f..0000000 --- a/Pipfile.lock +++ /dev/null @@ -1,58 +0,0 @@ -{ - "_meta": { - "hash": { - "sha256": "8739d581819011fea34feca8cc077062d6bdfee39c7b37a8ed48c5e0a8b14837" - }, - "pipfile-spec": 6, - "requires": { - "python_version": "3.7" - }, - "sources": [ - { - "name": "pypi", - "url": "https://pypi.org/simple", - "verify_ssl": true - } - ] - }, - "default": { - "certifi": { - "hashes": [ - "sha256:e4f3620cfea4f83eedc95b24abd9cd56f3c4b146dd0177e83a21b4eb49e21e50", - "sha256:fd7c7c74727ddcf00e9acd26bba8da604ffec95bf1c2144e67aff7a8b50e6cef" - ], - "version": "==2019.9.11" - }, - "chardet": { - "hashes": [ - "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", - "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" - ], - "version": "==3.0.4" - }, - "idna": { - "hashes": [ - "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", - "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c" - ], - "version": "==2.8" - }, - "requests": { - "hashes": [ - "sha256:502a824f31acdacb3a35b6690b5fbf0bc41d63a24a45c4004352b0242707598e", - "sha256:7bf2a778576d825600030a110f3c0e3e8edc51dfaafe1c146e39a2027784957b" - ], - "index": "pypi", - "version": "==2.21.0" - }, - "urllib3": { - "hashes": [ - "sha256:4c291ca23bbb55c76518905869ef34bdd5f0e46af7afe6861e8375643ffee1a0", - "sha256:9a247273df709c4fedb38c711e44292304f73f39ab01beda9f6b9fc375669ac3" - ], - "index": "pypi", - "version": "==1.24.2" - } - }, - "develop": {} -} diff --git a/evohomeclient2/__init__.py b/evohomeclient2/__init__.py index 92d76b8..f06ffb2 100644 --- a/evohomeclient2/__init__.py +++ b/evohomeclient2/__init__.py @@ -170,7 +170,9 @@ def _obtain_access_token(self, credentials): } payload.update(credentials) # merge the credentials into the payload - response = requests.post(url, data=payload, headers=HEADER_BASIC_AUTH, timeout=self.timeout) + response = requests.post( + url, data=payload, headers=HEADER_BASIC_AUTH, timeout=self.timeout + ) try: response.raise_for_status() @@ -312,6 +314,10 @@ def temperatures(self): """Return the current zone temperatures and set points.""" return self._get_single_heating_system().temperatures() + def schedules(self): + """Return the current zone schedules.""" + return self._get_single_heating_system().schedules() + def zone_schedules_backup(self, filename): """Back up the current system configuration to the given file.""" return self._get_single_heating_system().zone_schedules_backup(filename) diff --git a/evohomeclient2/controlsystem.py b/evohomeclient2/controlsystem.py index 1120882..de482d3 100644 --- a/evohomeclient2/controlsystem.py +++ b/evohomeclient2/controlsystem.py @@ -134,6 +134,24 @@ def temperatures(self): zone_info["setpointend"] = zone.setpointStatus["until"] yield zone_info + def schedules(self): + """Return a generator with the schedule of each zone.""" + if self.hotwater: + _LOGGER.info("Retrieving DHW schedule: %s...", self.hotwater.zoneId) + yield { + "name": "Domestic Hot Water", + "id": self.hotwater.zoneId, + "schedule": self.hotwater.schedule(), + } + + for zone in self._zones: + _LOGGER.info("Retrieving Zone schedule: %s - %s", zone.zoneId, zone.name) + yield { + "name": zone.name, + "id": zone.zoneId, + "schedule": zone.schedule(), + } + def zone_schedules_backup(self, filename): """Backup all zones on control system to the given file.""" _LOGGER.info( diff --git a/evohomeclient2/hotwater.py b/evohomeclient2/hotwater.py index e5dc227..00f8295 100644 --- a/evohomeclient2/hotwater.py +++ b/evohomeclient2/hotwater.py @@ -12,60 +12,71 @@ class HotWater(ZoneBase): def __init__(self, client, data, timeout=30): super(HotWater, self).__init__(client, timeout) - self.dhwId = None # pylint: disable=invalid-name + self.dhwId = None # pylint: disable=invalid-name self.__dict__.update(data) self.name = "" self.zoneId = self.dhwId - self.zone_type = 'domesticHotWater' + self.zone_type = "domesticHotWater" def _set_dhw(self, data): - headers = dict(self.client._headers()) # pylint: disable=protected-access - headers['Content-Type'] = 'application/json' + headers = dict(self.client._headers()) # pylint: disable=protected-access + headers["Content-Type"] = "application/json" url = ( "https://tccna.honeywell.com/WebAPI/emea/api/v1" "/domesticHotWater/%s/state" % self.dhwId ) - response = requests.put(url, data=json.dumps(data), headers=headers, timeout=self.timeout) + response = requests.put( + url, data=json.dumps(data), headers=headers, timeout=self.timeout + ) response.raise_for_status() def set_dhw_on(self, until=None): """Sets the DHW on until a given time, or permanently.""" if until is None: - data = {"Mode": "PermanentOverride", - "State": "On", - "UntilTime": None} + data = { + "Mode": "PermanentOverride", + "State": "On", + "UntilTime": None, + } else: - data = {"Mode": "TemporaryOverride", - "State": "On", - "UntilTime": until.strftime('%Y-%m-%dT%H:%M:%SZ')} + data = { + "Mode": "TemporaryOverride", + "State": "On", + "UntilTime": until.strftime("%Y-%m-%dT%H:%M:%SZ"), + } self._set_dhw(data) def set_dhw_off(self, until=None): """Sets the DHW off until a given time, or permanently.""" if until is None: - data = {"Mode": "PermanentOverride", - "State": "Off", - "UntilTime": None} + data = { + "Mode": "PermanentOverride", + "State": "Off", + "UntilTime": None, + } else: - data = {"Mode": "TemporaryOverride", - "State": "Off", - "UntilTime": until.strftime('%Y-%m-%dT%H:%M:%SZ')} + data = { + "Mode": "TemporaryOverride", + "State": "Off", + "UntilTime": until.strftime("%Y-%m-%dT%H:%M:%SZ"), + } self._set_dhw(data) def set_dhw_auto(self): """Sets the DHW to follow the schedule.""" - data = {"Mode": "FollowSchedule", - "State": "", - "UntilTime": None} + data = { + "Mode": "FollowSchedule", + "State": "", + "UntilTime": None, + } self._set_dhw(data) - def get_dhw_state(self): """Gets the DHW state.""" url = ( @@ -73,6 +84,8 @@ def get_dhw_state(self): "domesticHotWater/%s/status?" % self.dhwId ) - response = requests.get( url, headers=self.client._headers(), timeout=self.timeout) + response = requests.get( + url, headers=self.client._headers(), timeout=self.timeout + ) data = response.json() return data diff --git a/evohomeclient2/zone.py b/evohomeclient2/zone.py index 6eb013d..59dddd2 100644 --- a/evohomeclient2/zone.py +++ b/evohomeclient2/zone.py @@ -108,7 +108,9 @@ def _set_heat_setpoint(self, data): headers = dict(self.client._headers()) headers["Content-Type"] = "application/json" - response = requests.put(url, json.dumps(data), headers=headers, timeout=self.timeout) + response = requests.put( + url, json.dumps(data), headers=headers, timeout=self.timeout + ) response.raise_for_status() def cancel_temp_override(self):