Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make a single switcherapi class #809

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ asyncio.run(print_devices(60))
```python
async def control_power_plug(device_type, device_ip, device_id, device_key) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
# get the device current state
await api.get_state()
# turn the device on
Expand All @@ -62,7 +62,7 @@ asyncio.run(print_devices(60))
```python
async def control_water_heater(device_type, device_ip, device_id, device_key) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
# get the device current state
await api.get_state()
# turn the device on for 15 minutes
Expand Down Expand Up @@ -96,7 +96,7 @@ asyncio.run(print_devices(60))
```python
async def control_runner(device_type, device_ip, device_id, device_key, token) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType2Api(device_type, device_ip, device_id, device_key, token) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
# get the shutter current state, circuit number is 0
await api.get_shutter_state(0)
# open the shutter to 30%, circuit number is 0
Expand All @@ -122,7 +122,7 @@ asyncio.run(print_devices(60))
```python
async def control_breeze(device_type, device_ip, device_id, device_key, remote_manager, remote_id) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType2Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
# get the device current state
await api.get_breeze_state()
# initialize the Breeze RemoteManager and get the remote
Expand Down Expand Up @@ -152,7 +152,7 @@ asyncio.run(print_devices(60))
```python
async def control_light(device_type, device_ip, device_id, device_key, token) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType2Api(device_type, device_ip, device_id, device_key, token) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
# get the light current state, circuit number is 0
await api.get_light_state(0)
# turn on the light, circuit number is 0 (Only for Runner S11, Runner S12 and Lights)
Expand Down
8 changes: 4 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ We can use the Type1 API to gain the following capabilities:
```python
async def control_device(device_type, device_ip, device_id, device_key) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
# get the device current state (1)
await api.get_state()
# turn the device on for 15 minutes (2)
Expand Down Expand Up @@ -102,7 +102,7 @@ We can use the Type2 API to gain the following capabilities on Switcher Breeze,
```python
async def control_runner(device_type, device_ip, device_id, device_key, token) :
# for connecting to a device we need its type, id, login key, token and ip address
async with SwitcherType2Api(device_type, device_ip, device_id, device_key, token) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
# get the shutter current state, circuit number is 0
await api.get_shutter_state(0)
# open the shutter to 30%, circuit number is 0
Expand Down Expand Up @@ -135,7 +135,7 @@ asyncio.run(
```python
async def control_light(device_type, device_ip, device_id, device_key, token) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType2Api(device_type, device_ip, device_id, device_key, token) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
# get the light current state, circuit number is 0
await api.get_light_state(0)
# turn on the light, circuit number is 0 (Only for Runner S11, Runner S12 and Lights)
Expand All @@ -155,7 +155,7 @@ asyncio.run(
```python
async def control_breeze(device_type, device_ip, device_id, device_key, remote_manager, remote_id) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType2Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
# get the device current state (1)
await api.get_breeze_state()
# initialize the Breeze RemoteManager and get the remote (2)
Expand Down
50 changes: 17 additions & 33 deletions scripts/control_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pprint import PrettyPrinter
from typing import Any, Dict, List, Union

from aioswitcher.api import Command, SwitcherType1Api, SwitcherType2Api
from aioswitcher.api import Command, SwitcherApi
from aioswitcher.api.remotes import SwitcherBreezeRemoteManager
from aioswitcher.device import (
DeviceState,
Expand Down Expand Up @@ -442,9 +442,7 @@ async def get_thermostat_state(
token: Union[str, None] = None,
) -> None:
"""Use to launch a get_breeze_state request."""
async with SwitcherType2Api(
device_type, device_ip, device_id, device_key, token
) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
printer.pprint(asdict(await api.get_breeze_state(), verbose))


Expand All @@ -458,9 +456,7 @@ async def get_shutter_state(
token: Union[str, None] = None,
) -> None:
"""Use to launch a get_shutter_state request."""
async with SwitcherType2Api(
device_type, device_ip, device_id, device_key, token
) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
printer.pprint(asdict(await api.get_shutter_state(index), verbose))


Expand All @@ -472,7 +468,7 @@ async def get_state(
verbose: bool,
) -> None:
"""Use to launch a get_state request."""
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
printer.pprint(asdict(await api.get_state(), verbose))


Expand All @@ -492,9 +488,7 @@ async def control_thermostat(
token: Union[str, None] = None,
) -> None:
"""Control Breeze device."""
async with SwitcherType2Api(
device_type, device_ip, device_id, device_key, token
) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
printer.pprint(
asdict(
await api.control_breeze_device(
Expand All @@ -520,7 +514,7 @@ async def turn_on(
verbose: bool,
) -> None:
"""Use to launch a turn_on request."""
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
printer.pprint(asdict(await api.control_device(Command.ON, timer), verbose))


Expand All @@ -532,7 +526,7 @@ async def turn_off(
verbose: bool,
) -> None:
"""Use to launch a turn_off request."""
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
printer.pprint(asdict(await api.control_device(Command.OFF), verbose))


Expand All @@ -545,7 +539,7 @@ async def set_name(
verbose: bool,
) -> None:
"""Use to launch a set_name request."""
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
printer.pprint(asdict(await api.set_device_name(name), verbose))


Expand All @@ -560,7 +554,7 @@ async def set_auto_shutdown(
) -> None:
"""Use to launch a set_auto_shutdown request."""
td_val = timedelta(hours=hours, minutes=minutes)
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
printer.pprint(asdict(await api.set_auto_shutdown(td_val), verbose))


Expand All @@ -572,7 +566,7 @@ async def get_schedules(
verbose: bool,
) -> None:
"""Use to launch a get_schedules request."""
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
response = await api.get_schedules()
if verbose:
printer.pprint({"unparsed_response": response.unparsed_response})
Expand All @@ -591,7 +585,7 @@ async def delete_schedule(
verbose: bool,
) -> None:
"""Use to launch a delete_schedule request."""
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
printer.pprint(asdict(await api.delete_schedule(schedule_id), verbose))


Expand All @@ -606,7 +600,7 @@ async def create_schedule(
verbose: bool,
) -> None:
"""Use to launch a create_schedule request."""
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
printer.pprint(
asdict(
await api.create_schedule(
Expand All @@ -629,9 +623,7 @@ async def stop_shutter(
token: Union[str, None] = None,
) -> None:
"""Stop shutter."""
async with SwitcherType2Api(
device_type, device_ip, device_id, device_key, token
) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
printer.pprint(
asdict(
await api.stop_shutter(index),
Expand All @@ -651,9 +643,7 @@ async def set_shutter_position(
token: Union[str, None] = None,
) -> None:
"""Use to set the shutter position."""
async with SwitcherType2Api(
device_type, device_ip, device_id, device_key, token
) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
printer.pprint(
asdict(
await api.set_position(position, index),
Expand All @@ -672,9 +662,7 @@ async def get_light_state(
token: Union[str, None] = None,
) -> None:
"""Use to launch a get_light_state request."""
async with SwitcherType2Api(
device_type, device_ip, device_id, device_key, token
) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
printer.pprint(asdict(await api.get_light_state(index), verbose))


Expand All @@ -688,9 +676,7 @@ async def turn_on_light(
token: Union[str, None] = None,
) -> None:
"""Use for turn on light."""
async with SwitcherType2Api(
device_type, device_ip, device_id, device_key, token
) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
printer.pprint(asdict(await api.set_light(DeviceState.ON, index), verbose))


Expand All @@ -704,9 +690,7 @@ async def turn_off_light(
token: Union[str, None] = None,
) -> None:
"""Use for turn off light."""
async with SwitcherType2Api(
device_type, device_ip, device_id, device_key, token
) as api:
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
printer.pprint(asdict(await api.set_light(DeviceState.OFF, index), verbose))


Expand Down
Loading
Loading