Giter VIP home page Giter VIP logo

smart-home-python's Introduction

Actions on Google: Python Smart Home

Python lib to handle the Google Actions

https://developers.google.com/assistant/smarthome/develop/process-intents

Example

from smart_home import RequestHandler
from smart_home import actions


class MyActionHandler(RequestHandler):
    def __init__(self, led, name, nickname, fullname, room):
        # Provide a list of devices (smart_home.device.Device)
        super().__init__(None, my_list_of_rgb_lights_devices, mapping_from_acitons_to_handlers)

Example of mapping from actions to handlers:

from smart_home import actions
{
    actions.ACTION_COMMAND_BRIGHTNESS_ABSOLUTE: self.set_brightness,
    actions.ACTION_COMMAND_COLOR_ABSOLUTE: self.set_color,
    actions.ACTION_COMMAND_ON_OFF: self.set_on_off,
}

Then override the format_device_state(self, device_ids) method which should format the state of the given device ids

Example:

def format_device_state(self, device_ids):
    device_status = dict()
    for device_id in device_ids:

        device = self.get_device(device_id)

        if not device:
            raise error.RequestError(
                self.current_request_id, error.ERROR_DEVICE_NOT_FOUND
            )

        device_obj = device.obj

        device_status[device_id] = {
            "on": device_obj.is_on,
            "online": True,
            "brightness": round(device_obj.brightness * 100.0),
            "color": {"spectrumRGB": device_obj.color_rgb_spectrum},
        }
    return device_status

License

See LICENSE.

smart-home-python's People

Contributors

jacobh2 avatar

Watchers

 avatar  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.