Giter Site home page Giter Site logo

ayal / aioswitcher Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tomerfi/aioswitcher

0.0 0.0 0.0 3.77 MB

PyPi module integrating with various Switcher devices

Home Page: https://aioswitcher.tomfi.info

License: Apache License 2.0

Python 99.03% Makefile 0.97%

aioswitcher's Introduction

Switcher Python Integration
pypi-version pypi-downloads license-badge

gh-build-status gh-pages-status codecov

PyPi module integrating with various Switcher devices.
Check out the wiki pages for a list of supported devices.

pip install aioswitcher
Documentation Wiki Contributing

Example Usage

State Bridge
async def print_devices(delay):
    def on_device_found_callback(device):
        # a switcher device will broadcast a state message approximately every 4 seconds
        print(asdict(device))

    async with SwitcherBridge(on_device_found_callback):
        await asyncio.sleep(delay)

# run the bridge for 60 seconds
asyncio.run(print_devices(60))
Power Plug API
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:
        # get the device current state
        await api.get_state()
        # turn the device on
        await api.control_device(Command.ON)
        # turn the device off
        await api.control_device(Command.OFF)
        # set the device name to 'my new name'
        await api.set_device_name("my new name")

asyncio.run(control_power_plug(DeviceType.POWER_PLUG, "111.222.11.22", "ab1c2d", "00"))
Water Heater API
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:
        # get the device current state
        await api.get_state()
        # turn the device on for 15 minutes
        await api.control_device(Command.ON, 15)
        # turn the device off
        await api.control_device(Command.OFF)
        # set the device name to 'my new name'
        await api.set_device_name("my new name")
        # configure the device for 02:30 auto shutdown
        await api.set_auto_shutdown(timedelta(hours=2, minutes=30))
        # get the schedules from the device
        await api.get_schedules()
        # delete and existing schedule with id 1
        await api.delete_schedule("1")
        # create a new recurring schedule for 13:00-14:30
        # executing on sunday and friday
        await api.create_schedule("13:00", "14:30", {Days.SUNDAY, Days.FRIDAY})

asyncio.run(control_water_heater(DeviceType.MINI, "111.222.11.22", "ab1c2d" , "00"))
asyncio.run(control_water_heater(DeviceType.TOUCH, "111.222.11.22", "ab1c2d" , "00"))
asyncio.run(control_water_heater(DeviceType.V2_ESP, "111.222.11.22", "ab1c2d" , "00"))
asyncio.run(control_water_heater(DeviceType.V2_QCA, "111.222.11.22", "ab1c2d" , "00"))
asyncio.run(control_water_heater(DeviceType.V4, "111.222.11.22", "ab1c2d" , "00"))
Runner API
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:
        # get the device current state
        await api.get_shutter_state()
        # open the shutter to 30%, circuit number is 0
        await api.set_position(30, 0)
        # stop the shutter if currently rolling, circuit number is 0
        await api.stop_shutter(0)
        # turn on the light, circuit number is 0 (Only for Runner S11 and Runner S12)
        await api.api.set_light(DeviceState.ON, 0)
        # turn off the light, circuit number is 0 (Only for Runner S11 and Runner S12)
        await api.api.set_light(DeviceState.OFF, 0)

asyncio.run(control_runner(DeviceType.RUNNER, "111.222.11.22", "ab1c2d", "00"))
asyncio.run(control_runner(DeviceType.RUNNER_MINI, "111.222.11.22", "ab1c2d", "00"))
asyncio.run(control_runner(DeviceType.RUNNER_S11, "111.222.11.22", "ab1c2d", "00", "zvVvd7JxtN7CgvkD1Psujw=="))
Breeze API
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:
        # get the device current state
        await api.get_breeze_state()
        # initialize the Breeze RemoteManager and get the remote
        remote = remote_manager.get_remote(remote_id)
        # prepare a control command that turns on the Breeze
        # set to 24 degree (Celsius) cooling with vertical swing
        # send command to the device
        await api.control_breeze_device(
            remote,
            DeviceState.ON,
            ThermostatMode.COOL,
            24,
            ThermostatFanLevel.MEDIUM,
            ThermostatSwing.ON,
        )

# create the remote manager outside the context for re-using
remote_manager = SwitcherBreezeRemoteManager()
asyncio.run(control_breeze(DeviceType.BREEZE, "111.222.11.22", "ab1c2d", "00", remote_manager, "DLK65863"))

Command Line Helper Scripts

  • discover_devices.py can discover devices and their states (can be run by poetry run discover_devices).
  • control_device.py can control a device (can be run by poetry run control_device).
  • get_device_login_key.py can get a device login key (can be run by poetry run get_device_login_key).
  • validate_token.py can validate a device token which is a must for newer devices, used for communicating with devices (can be run by poetry run validate_token).

Disclaimer

This is NOT an official module and it is NOT officially supported by the vendor.
That said, thanks are in order to all the people at Switcher for their cooperation and general support.

Contributors all-contributors

Thanks goes to these wonderful people (emoji key):

Aviad Golan
Aviad Golan

๐Ÿ”ฃ
Dolev Ben Aharon
Dolev Ben Aharon

๐Ÿ“–
Fabian Affolter
Fabian Affolter

๐Ÿ’ป
Itzik Ephraim
Itzik Ephraim

๐Ÿ’ป
Kesav890
Kesav890

๐Ÿ“–
Liad Avraham
Liad Avraham

๐Ÿ’ป
Marc Mueller
Marc Mueller

๐Ÿ’ป
Or Bin
Or Bin

๐Ÿ’ป
Roeeeee
Roeeeee

๐Ÿ’ป
Shai rod
Shai rod

๐Ÿ”ฃ
Shay Levy
Shay Levy

๐Ÿ’ป ๐Ÿค” ๐Ÿšง
YogevBokobza
YogevBokobza

๐Ÿ’ป โš ๏ธ ๐Ÿšง
Yuval Moran
Yuval Moran

๐Ÿ’ป โš ๏ธ
dmatik
dmatik

๐Ÿ“ ๐Ÿค” ๐Ÿ““
jafar-atili
jafar-atili

๐Ÿ’ป ๐Ÿ“–

aioswitcher's People

Contributors

tomerfi avatar dependabot[bot] avatar thecode avatar dependabot-preview[bot] avatar jafar-atili avatar allcontributors[bot] avatar yogevbokobza avatar greenkeeper[bot] avatar orbin avatar cdce8p avatar oranja avatar dolby360 avatar fabaff avatar kesav890 avatar liadav avatar 5c077m4n avatar gmyuval avatar fossabot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.