Skip to content

Commit

Permalink
Merge pull request #196 from webdjoe/update-readme
Browse files Browse the repository at this point in the history
update readme
  • Loading branch information
webdjoe authored Jul 22, 2023
2 parents c699120 + a452dd2 commit 2d70bb4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 34 deletions.
102 changes: 71 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -921,39 +921,79 @@ from pyvesync import VeSync
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

USERNAME = "YOUR USERNAME"
PASSWORD = "YOUR PASSWORD"

def test_device():
# Instantiate VeSync class and login
manager = VeSync(user, password, debug=True)
if manager.login() == False
logger("Unable to login")
return

# Test specific device
# If this were a humidifier and there is only one humidifier/purifier
# You can access it with the device index
fan = manager.fans[0]
# or loop through the fan devices and test for device with "My Device" name
# Use lower() to avoid capitalization issues
my_device_name = "My Device"
fan = None
for dev in manager.fans:
if dev.name.lower() == my_device_name.lower()
fan = dev
if fan == None:
logger.debug("Device not found")
logger.debug("Devices found - \n" + json.dumps(manager._dev_list))
return

# Test all device methods and functionality
# Be aware some devices lose internet connectivity if turned off
fan.turn_on()
fan.turn_off()
fan.sleep_mode()

# Make script runnable from command line
# Instantiate VeSync class and login
manager = VeSync(USERNAME, PASSWORD, debug=True)
if manager.login() == False:
logger.debug("Unable to login")
return

# Pull and update devices
manager.update()

fan = None
logger.debug(str(manager.fans))

for dev in manager.fans:
# Print all device info
logger.debug(dev.device_name + "\n")
logger.debug(dev.display())

# Find correct device
if dev.device_name.lower() == DEVICE_NAME.lower():
fan = dev
break

if fan == None:
logger.debug("Device not found")
logger.debug("Devices found - \n %s", str(manager._dev_list))
return


logger.debug('--------------%s-----------------' % fan.device_name)
logger.debug(dev.display())
logger.debug(dev.displayJSON())
# Test all device methods and functionality
# Test Properties
logger.debug("Fan is on - %s", fan.is_on)
logger.debug("Modes - %s", fan.modes)
logger.debug("Fan Level - %s", fan.fan_level)
logger.debug("Fan Air Quality - %s", fan.air_quality)
logger.debug("Screen Status - %s", fan.screen_status)

fan.turn_on()
fan.turn_off()
fan.sleep_mode()
fan.auto_mode()
fan.manual_mode()
fan.change_fan_speed(3)
fan.change_fan_speed(2)
fan.child_lock_on()
fan.child_lock_off()
fan.turn_off_display()
fan.turn_on_display()

fan.set_light_detection_on()
logger.debug(fan.light_detection_state)
logger.debug(fan.light_detection)

# Only on Vital 200S
fan.pet_mode()

logger.debug("Set Fan Speed - %s", fan.set_fan_speed)
logger.debug("Current Fan Level - %s", fan.fan_level)
logger.debug("Current mode - %s", fan.mode)

# Display all device info
logger.debug(dev.display())
logger.debug(dev.displayJSON())

if __name__ == "__main__":
logger.debug("Testing device")
test_device()
logger.debug("Testing device")
test_device()
...

```
Expand Down
6 changes: 3 additions & 3 deletions src/pyvesync/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ def call_api(api: str, method: str, json_object: Optional[dict] = None,
logger.debug("[%s] calling '%s' api", method, api)
logger.debug("API call URL: \n %s%s", API_BASE_URL, api)
logger.debug("API call headers: \n %s",
Helpers.redactor(json.dumps(headers)))
Helpers.redactor(json.dumps(headers, indent=2)))
logger.debug("API call json: \n %s",
Helpers.redactor(json.dumps(json_object)))
Helpers.redactor(json.dumps(json_object, indent=2)))
if method.lower() == 'get':
r = requests.get(
API_BASE_URL + api, json=json_object, headers=headers,
Expand All @@ -234,7 +234,7 @@ def call_api(api: str, method: str, json_object: Optional[dict] = None,
if r.content:
response = r.json()
logger.debug("API response: \n\n %s \n ",
Helpers.redactor(json.dumps(response)))
Helpers.redactor(json.dumps(response, indent=2)))
else:
logger.debug('Unable to fetch %s%s', API_BASE_URL, api)
return response, status_code
Expand Down

0 comments on commit 2d70bb4

Please sign in to comment.