-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
229 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# light_01 | ||
|
||
This example demonstrates how to create a simple light source and control it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import asyncio | ||
import logging | ||
|
||
from pyown.client import Client | ||
from pyown.items import Gateway | ||
|
||
|
||
async def run(host: str, port: int, password: str): | ||
client = Client( | ||
host=host, | ||
port=port, | ||
password=password, | ||
) | ||
|
||
await client.start() | ||
|
||
gateway = Gateway( | ||
client=client | ||
) | ||
|
||
# get ip address of the gateway | ||
ip = await gateway.get_ip() | ||
print(ip) | ||
|
||
# get the model of the gateway | ||
model = await gateway.get_model() | ||
print(model.name) | ||
|
||
# get datetime of the gateway | ||
datetime = await gateway.get_datetime() | ||
print(datetime) | ||
|
||
# get the kernel version of the gateway | ||
kernel = await gateway.get_kernel_version() | ||
print(kernel) | ||
|
||
await client.close() | ||
|
||
|
||
def main(host: str, port: int, password: str): | ||
# Set the logging level to DEBUG | ||
logging.basicConfig( | ||
level=logging.DEBUG, | ||
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", | ||
datefmt="%Y-%m-%d %H:%M:%S", | ||
) | ||
|
||
# Run the asyncio event loop | ||
asyncio.run(run(host, port, password)) | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--host", type=str, help="The host to connect to", default="192.168.1.35") | ||
parser.add_argument("--port", type=int, help="The port to connect to", default=20000) | ||
parser.add_argument("--password", type=str, help="The password to authenticate with", default="12345") | ||
|
||
args = parser.parse_args() | ||
|
||
main(args.host, args.port, args.password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# light_01 | ||
|
||
This example demonstrates how to create a simple light source and control it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import asyncio | ||
import logging | ||
|
||
from black import datetime | ||
|
||
from pyown.client import Client, SessionType | ||
from pyown.items import Gateway, WhatGateway | ||
|
||
|
||
async def on_time_change(gateway: Gateway, time: datetime.time): | ||
print(f"Time of the gateway is now {time}") | ||
|
||
|
||
async def run(host: str, port: int, password: str): | ||
client = Client( | ||
host=host, | ||
port=port, | ||
password=password, | ||
session_type=SessionType.EventSession | ||
) | ||
|
||
Gateway.register_callback( | ||
WhatGateway.TIME, | ||
on_time_change | ||
) | ||
|
||
await client.start() | ||
await client.loop() | ||
|
||
|
||
def main(host: str, port: int, password: str): | ||
# Set the logging level to DEBUG | ||
logging.basicConfig( | ||
level=logging.WARN, | ||
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", | ||
datefmt="%Y-%m-%d %H:%M:%S", | ||
) | ||
|
||
# Run the asyncio event loop | ||
asyncio.run(run(host, port, password)) | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--host", type=str, help="The host to connect to", default="192.168.1.35") | ||
parser.add_argument("--port", type=int, help="The port to connect to", default=20000) | ||
parser.add_argument("--password", type=str, help="The password to authenticate with", default="12345") | ||
|
||
args = parser.parse_args() | ||
|
||
main(args.host, args.port, args.password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from .lighting import Light, Dimmer | ||
from .lighting import * | ||
from .automation import * | ||
from .gateway import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .gateway import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters