Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Implemented setting datetime. (#17)
Browse files Browse the repository at this point in the history
* Implemented setting datetime. Note the specifics w.r.t. urlencoding and no leading zeros

(cherry picked from commit 3a3b152)

* make pylint happy

* making pylint even happier
  • Loading branch information
gjdv authored Feb 14, 2023
1 parent 14c56e7 commit 0bee5fc
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions daikinapi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Python module to get metrics from and control Daikin airconditioners
"""

import datetime
import logging
import urllib.parse

Expand Down Expand Up @@ -194,10 +194,28 @@ def _get_datetime(self):
"""
Example:
ret=OK,sta=1,cur=2022/12/01 22:01:02,reg=eu,dst=1,zone=10
:return:
:return: dict
"""
return self._get("/common/get_datetime")

def _set_datetime(self, date_time=None):
"""
Example:
ret=OK
:return: None
"""
if date_time is None:
date_time = datetime.datetime.now()
date_time = date_time.astimezone(tz=datetime.timezone.utc)
data = {
'lpw': '',
'date': f'{date_time.year:d}/{date_time.month:d}/{date_time.day:d}',
'zone': 'GMT',
'time': f'{date_time.hour:d}:{date_time.minute:d}:{date_time.second:d}',
}
data = urllib.parse.urlencode(data)
return self._set("/common/notify_date_time", data)

def _do_reboot(self):
return self._get("/common/reboot")

Expand Down Expand Up @@ -284,8 +302,8 @@ def datetime(self):
:return: string of datetime on the device (yyyy/mm/dd HH:MM:SS),
or None if not retrievable
"""
datetime = self._get_datetime()["cur"]
return datetime if datetime != "-" else None
date_time = self._get_datetime()["cur"]
return date_time if date_time != "-" else None

@power.setter
def power(self, value):
Expand Down Expand Up @@ -316,6 +334,10 @@ def wifi_settings(self, value):
ssid, key = value
self._set_wifi(ssid, key)

@datetime.setter
def datetime(self, value):
self._set_datetime(date_time=value)

def _control_set(self, key, value):
"""
set a get_control() item via one of the property.setters
Expand Down

0 comments on commit 0bee5fc

Please sign in to comment.