Skip to content

Commit

Permalink
Improve client.tz_offset getter
Browse files Browse the repository at this point in the history
Closed #16
  • Loading branch information
h4 committed Apr 8, 2020
1 parent 3577184 commit 5b4262e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lywsd02/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,19 @@ def time(self):

@time.setter
def time(self, dt: datetime):
if self._tz_offset is not None:
tz_offset = self._tz_offset
elif time.daylight != 0:
tz_offset = int(-time.altzone / 3600)
else:
tz_offset = int(-time.timezone / 3600)

data = struct.pack('Ib', int(dt.timestamp()), tz_offset)
data = struct.pack('Ib', int(dt.timestamp()), self.tz_offset)
with self.connect():
ch = self._peripheral.getCharacteristics(uuid=UUID_TIME)[0]
ch.write(data, withResponse=True)

@property
def tz_offset(self):
return self._tz_offset
if self._tz_offset is not None:
return self._tz_offset
elif time.daylight:
return -time.altzone // 3600
else:
return -time.timezone // 3600

@tz_offset.setter
def tz_offset(self, tz_offset: int):
Expand Down

0 comments on commit 5b4262e

Please sign in to comment.