Skip to content

Commit 96a762d

Browse files
committed
Improve docs for pywemo/subscribe
1 parent 032f148 commit 96a762d

3 files changed

Lines changed: 105 additions & 2 deletions

File tree

pywemo/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# API Documentation
2+
3+
For example usage and installation instructions see
4+
[README.rst](https://github.com/pywemo/pywemo/blob/main/README.rst)
5+
6+
## General structure of the pyWeMo API
7+
8+
### Discovery
9+
10+
The `pywemo.discovery` module contains methods to locate WeMo devices on a
11+
network. For example, use the following to discover all devices on the
12+
network:
13+
14+
```python
15+
>>> import pywemo
16+
>>> devices = pywemo.discover_devices()
17+
>>> print(devices)
18+
[<WeMo Insight "AC Insight">]
19+
```
20+
21+
Or, if you know the IP address of the device, use this example.
22+
23+
```python
24+
>>> import pywemo
25+
>>> url = pywemo.setup_url_for_address("192.168.1.192")
26+
>>> print(url)
27+
http://192.168.1.192:49153/setup.xml
28+
>>> device = pywemo.device_from_description(url)
29+
>>> print(device)
30+
[<WeMo Insight "AC Insight">]
31+
```
32+
33+
### Devices
34+
35+
The device(s) returned by the discovery methods above will be instances of one
36+
of the classes below. These classes, used for communicating with the various,
37+
WeMo devices are in submodules under the `pywemo.ouimeaux_device` module. They
38+
can also be accessed as top-level members of the pywemo module.
39+
40+
WeMo Model|Alias / Class
41+
----------|-------------
42+
F7C031 |`pywemo.Bridge` / `pywemo.ouimeaux_device.bridge.Bridge`
43+
F7C050 |`pywemo.CoffeeMaker` / `pywemo.ouimeaux_device.coffeemaker.CoffeeMaker`
44+
F7C045 |`pywemo.CrockPot` / `pywemo.ouimeaux_device.crockpot.CrockPot`
45+
F7C059 |`pywemo.DimmerLongPress` / `pywemo.ouimeaux_device.dimmer.DimmerLongPress`
46+
WDS060 |`pywemo.DimmerV2` / `pywemo.ouimeaux_device.dimmer.DimmerV2`
47+
F7C046 |`pywemo.Humidifier` / `pywemo.ouimeaux_device.humidifier.Humidifier`
48+
F7C029 |`pywemo.Insight` / `pywemo.ouimeaux_device.insight.Insight`
49+
F7C030 |`pywemo.LightSwitchLongPress` / `pywemo.ouimeaux_device.lightswitch.LightSwitchLongPress`
50+
WLS040 |`pywemo.LightSwitchLongPress` / `pywemo.ouimeaux_device.lightswitch.LightSwitchLongPress`
51+
WLS0403 |`pywemo.LightSwitchLongPress` / `pywemo.ouimeaux_device.lightswitch.LightSwitchLongPress`
52+
F7C043 |`pywemo.Maker` / `pywemo.ouimeaux_device.maker.Maker`
53+
F7C028 |`pywemo.Motion` / `pywemo.ouimeaux_device.motion.Motion`
54+
WSP090 |`pywemo.OutdoorPlug` / `pywemo.ouimeaux_device.outdoor_plug.OutdoorPlug`
55+
F7C027 |`pywemo.Switch` / `pywemo.ouimeaux_device.switch.Switch`
56+
F7C063 |`pywemo.Switch` / `pywemo.ouimeaux_device.switch.Switch`
57+
WSP080 |`pywemo.Switch` / `pywemo.ouimeaux_device.switch.Switch`
58+
59+
The following are base classes of all of the above device classes.
60+
61+
* pywemo.ouimeaux_device.Device: Provides common methods for getting/setting
62+
device state.
63+
* pywemo.ouimeaux_device.api.xsd_types.DeviceDescription: Provides information
64+
about the device name, mac address, firmware version, serial number, etc.
65+
66+
### Subscriptions
67+
68+
Most WeMo devices support a push/callback model for reporting state changes.
69+
The `pywemo.subscribe` module provides a way to subscribe to push events.

pywemo/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""Lightweight Python module to discover and control WeMo devices."""
1+
r"""Lightweight Python module to discover and control WeMo devices.
2+
.. include:: README.md
3+
"""
24
# flake8: noqa F401
35

46
from .discovery import (

pywemo/subscribe.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
1-
"""Module to listen for wemo events."""
1+
"""Module to listen for WeMo events.
2+
3+
Example usage:
4+
5+
```python
6+
import pywemo
7+
# The SubscriptionRegistry maintains push subscriptions to each endpoint
8+
# of a device.
9+
registry = pywemo.SubscriptionRegistry()
10+
registry.start()
11+
12+
device = ... # See example of discovering devices in the pywemo module.
13+
14+
# Start subscribing to push notifications of state changes.
15+
registry.register(device)
16+
17+
def push_notification(device, event, params):
18+
'''Notify device of state change and get new device state.'''
19+
processed_update = device.subscription_update(event, params)
20+
state = device.get_state(force_update=not processed_update)
21+
print(f"Device state: {state}")
22+
23+
# Register a callback to receive state push notifications.
24+
registry.on(device, None, push_notification)
25+
26+
# Do some work.
27+
# time.sleep(60)
28+
29+
# Stop the registry
30+
registry.unregister(device)
31+
registry.stop()
32+
```
33+
"""
234
from __future__ import annotations
335

436
import collections

0 commit comments

Comments
 (0)