Skip to content

Commit

Permalink
Added example to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kbickar committed Aug 21, 2020
1 parent 82fa08d commit e52644a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ https://gist.github.com/mbrownnycnyc/db3209a1045746f5e287ea6b6631e19c
## Local Device Emulation
The SenseLink class emulates the energy monitoring functionality of TP-Link Kasa HS110 Smart Plugs
and allows you to report "custom" power usage to your Sense Home Energy Monitor. This requires
enabling "TP-Link HS110/HS300 Smart Plug" in the Sense app
enabling "TP-Link HS110/HS300 Smart Plug" in the Sense app.

Based off the work of https://github.com/cbpowell/SenseLink

### Contributors

Expand All @@ -33,7 +35,7 @@ https://github.com/kbickar
pip install sense_energy
```

### Example Usage:
### Web API Example Usage:
```python
sense = Senseable()
sense.authenticate(username, password)
Expand All @@ -56,3 +58,23 @@ and `get_realtime()` will retrieve the latest real time stats.

The get_realtime() is by default rate limited to one call per 30 seconds. This can
be modified by setting the Senseable object attribute `rate_limit` to a different value.

### Local emulation Example Usage:
```python
async def test():
import time
def test_devices():
devices = [PlugInstance("lamp1", start_time=time()-20, alias="Lamp", power=10),
PlugInstance("fan1", start_time=time()-300, alias="Fan", power=140)]
for d in devices:
yield d
sl = SenseLink(test_devices)
await sl.start()
try:
await asyncio.sleep(180) # Serve for 3 minutes
finally:
await sl.stop()

if __name__ == "__main__":
asyncio.run(test())
```
17 changes: 0 additions & 17 deletions sense_energy/SenseLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,3 @@ async def start(self):

async def stop(self):
self.transport.close()

async def test():
import time
def test_devices():
devices = [PlugInstance("lamp1", time()-20, alias="Lamp", power=10),
PlugInstance("fan1", time()-300, alias="Fan", power=140)]
for d in devices:
yield d
sl = SenseLink(test_devices)
await sl.start()
try:
await asyncio.sleep(180) # Serve for 3 minutes
finally:
await sl.stop()

if __name__ == "__main__":
asyncio.run(test())
4 changes: 2 additions & 2 deletions sense_energy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
if sys.version_info >= (3, 5):
from .asyncsenseable import ASyncSenseable
from .PlugInstance import PlugInstance
from .SenseLink import SenseLink
from .PlugInstance import PlugInstance
from .SenseLink import SenseLink

__version__ = "0.7.0"

0 comments on commit e52644a

Please sign in to comment.