Skip to content

Commit 74c07da

Browse files
committed
Start adding docstrings
1 parent 5a07432 commit 74c07da

File tree

2 files changed

+168
-9
lines changed

2 files changed

+168
-9
lines changed

src/pyvesync/vesync.py

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,45 @@ def kitchen(dev_type, config, manager):
7474

7575

7676
class VeSync: # pylint: disable=function-redefined
77-
"""VeSync API functions."""
77+
"""VeSync Manager Class."""
7878

7979
def __init__(self, username, password, time_zone=DEFAULT_TZ,
8080
debug=False, redact=True):
81-
"""Initialize VeSync class with username, password and time zone."""
81+
"""Initialize VeSync Manager.
82+
83+
This class is used as the manager for all VeSync objects, all methods and
84+
API calls are performed from this class. Time zone, debug and redact are
85+
optional. Time zone must be a string of an IANA time zone format. Once
86+
class is instantiated, call `manager.login()` to log in to VeSync servers,
87+
which returns `True` if successful. Once logged in, call `manager.update()`
88+
to retrieve devices and update device details.
89+
90+
Parameters:
91+
-----------
92+
username : str
93+
VeSync account username (usually email address)
94+
password : str
95+
VeSync account password
96+
time_zone : str, optional
97+
Time zone for device from IANA database, by default DEFAULT_TZ
98+
debug : bool, optional
99+
Enable debug logging, by default False
100+
redact : bool, optional
101+
Redact sensitive information in logs, by default True
102+
103+
Attributes
104+
----------
105+
fans : list
106+
List of VeSyncFan objects for humidifiers and air purifiers
107+
outlets : list
108+
List of VeSyncOutlet objects for smart plugs
109+
switches : list
110+
List of VeSyncSwitch objects for wall switches
111+
bulbs : list
112+
List of VeSyncBulb objects for smart bulbs
113+
kitchen : list
114+
List of VeSyncKitchen objects for smart kitchen appliances
115+
"""
82116
self.debug = debug
83117
if debug: # pragma: no cover
84118
logger.setLevel(logging.DEBUG)
@@ -308,7 +342,15 @@ def get_devices(self) -> bool:
308342
return proc_return
309343

310344
def login(self) -> bool:
311-
"""Return True if log in request succeeds."""
345+
"""Log into VeSync server.
346+
347+
Username and password are provided when class is instantiated.
348+
349+
Returns
350+
-------
351+
bool
352+
True if login successful, False if not
353+
"""
312354
user_check = isinstance(self.username, str) and len(self.username) > 0
313355
pass_check = isinstance(self.password, str) and len(self.password) > 0
314356
if user_check is False:
@@ -346,7 +388,16 @@ def device_time_check(self) -> bool:
346388
return False
347389

348390
def update(self) -> None:
349-
"""Fetch updated information about devices."""
391+
"""Fetch updated information about devices.
392+
393+
Pulls devices list from VeSync and instantiates any new devices. Devices
394+
are stored in the instance attributes `outlets`, `switches`, `fans`, and
395+
`bulbs`. The `_device_list` attribute is a dictionary of these attributes.
396+
397+
Returns
398+
-------
399+
None
400+
"""
350401
if self.device_time_check():
351402

352403
if not self.enabled:

src/pyvesync/vesyncfan.py

Lines changed: 113 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,52 @@ class VeSyncAirBypass(VeSyncBaseDevice):
168168
"""Base class for Levoit Purifier Bypass API Calls."""
169169

170170
def __init__(self, details: Dict[str, list], manager):
171-
"""Initialize air devices."""
171+
"""Initialize air purifier devices.
172+
173+
Instantiated by VeSync manager object. Inherits from
174+
VeSyncBaseDevice class.
175+
176+
Arguments
177+
----------
178+
details : dict
179+
Dictionary of device details
180+
manager : VeSync
181+
Instantiated VeSync object used to make API calls
182+
183+
Attributes
184+
----------
185+
modes : list
186+
List of available operation modes for device
187+
air_quality_feature : bool
188+
True if device has air quality sensor
189+
details : dict
190+
Dictionary of device details
191+
timer : Timer
192+
Timer object for device, None if no timer exists. See `Timer` class
193+
config : dict
194+
Dictionary of device configuration
195+
196+
Notes
197+
-----
198+
The `details` attribute holds device information that is updated when
199+
the `update()` method is called. An example of the `details` attribute:
200+
>>> {
201+
>>> 'filter_life': 0,
202+
>>> 'mode': 'manual',
203+
>>> 'level': 0,
204+
>>> 'display': False,
205+
>>> 'child_lock': False,
206+
>>> 'night_light': 'off',
207+
>>> 'air_quality': 0 # air quality level
208+
>>> 'air_quality_value': 0, # PM2.5 value from device,
209+
>>> 'display_forever': False
210+
>>> }
211+
212+
See Also
213+
--------
214+
VeSyncBaseDevice : Parent class for all VeSync devices
215+
216+
"""
172217
super().__init__(details, manager)
173218
self.enabled = True
174219
self._config_dict = model_features(self.device_type)
@@ -297,7 +342,31 @@ def update(self):
297342
self.get_details()
298343

299344
def get_timer(self) -> Optional[Timer]:
300-
"""Retrieve running timer from purifier."""
345+
"""Retrieve running timer from purifier.
346+
347+
Returns Timer object if timer is running, None if no timer is running.
348+
349+
Arguments
350+
----------
351+
None
352+
353+
Returns
354+
-------
355+
Timer or None
356+
357+
Notes
358+
-----
359+
Timer object tracks the time remaining based on the last update. Timer
360+
properties include `status`, `time_remaining`, `duration`, `action`,
361+
`paused` and `done`. The methods `start()`, `end()` and `pause()`
362+
are available but should be called through the purifier object
363+
to update through the API.
364+
365+
See Also
366+
--------
367+
Timer : Timer object used to track device timers
368+
369+
"""
301370
head, body = self.build_api_dict('getTimer')
302371
body['payload']['data'] = {}
303372
if not head and not body:
@@ -345,6 +414,11 @@ def set_timer(self, timer_duration: int) -> bool:
345414
----------
346415
timer_duration: int
347416
Duration of timer in seconds
417+
418+
Returns
419+
-------
420+
bool
421+
348422
"""
349423
if self.device_status != 'on':
350424
logger.debug("Can't set timer when device is off")
@@ -382,7 +456,15 @@ def set_timer(self, timer_duration: int) -> bool:
382456
return True
383457

384458
def clear_timer(self) -> bool:
385-
"""Clear timer."""
459+
"""Clear timer.
460+
461+
Returns True if no error is returned from API call.
462+
463+
Returns
464+
-------
465+
bool
466+
467+
"""
386468
self.get_timer()
387469
if self.timer is None:
388470
logger.debug('No timer to clear')
@@ -465,7 +547,20 @@ def child_lock_off(self) -> bool:
465547
return self.set_child_lock(False)
466548

467549
def set_child_lock(self, mode: bool) -> bool:
468-
"""Set Bypass child lock."""
550+
"""Set Bypass child lock.
551+
552+
Set child lock to on or off.
553+
554+
Arguments
555+
----------
556+
mode: bool
557+
True to turn child lock on, False to turn off
558+
559+
Returns
560+
-------
561+
bool
562+
563+
"""
469564
if mode not in (True, False):
470565
logger.debug('Invalid mode passed to set_child_lock - %s', mode)
471566
return False
@@ -519,7 +614,20 @@ def reset_filter(self) -> bool:
519614
return False
520615

521616
def mode_toggle(self, mode: str) -> bool:
522-
"""Set purifier mode - sleep or manual."""
617+
"""Set purifier mode - sleep or manual.
618+
619+
Set purifier mode based on devices available modes.
620+
621+
Arguments
622+
----------
623+
mode: str
624+
Mode to set purifier. Based on device modes in attribute `modes`
625+
626+
Returns
627+
-------
628+
bool
629+
630+
"""
523631
if mode.lower() not in self.modes:
524632
logger.debug('Invalid purifier mode used - %s',
525633
mode)

0 commit comments

Comments
 (0)