项目作者: Jacobh2

项目描述 :
Smart home lib for Actions on Google, for Python!
高级语言: Python
项目地址: git://github.com/Jacobh2/smart-home-python.git
创建时间: 2019-11-16T16:49:33Z
项目社区:https://github.com/Jacobh2/smart-home-python

开源协议:MIT License

下载


Actions on Google: Python Smart Home

Python lib to handle the Google Actions

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

Example

  1. from smart_home import RequestHandler
  2. from smart_home import actions
  3. class MyActionHandler(RequestHandler):
  4. def __init__(self, led, name, nickname, fullname, room):
  5. # Provide a list of devices (smart_home.device.Device)
  6. super().__init__(None, my_list_of_rgb_lights_devices, mapping_from_acitons_to_handlers)

Example of mapping from actions to handlers:

  1. from smart_home import actions
  2. {
  3. actions.ACTION_COMMAND_BRIGHTNESS_ABSOLUTE: self.set_brightness,
  4. actions.ACTION_COMMAND_COLOR_ABSOLUTE: self.set_color,
  5. actions.ACTION_COMMAND_ON_OFF: self.set_on_off,
  6. }

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

Example:

  1. def format_device_state(self, device_ids):
  2. device_status = dict()
  3. for device_id in device_ids:
  4. device = self.get_device(device_id)
  5. if not device:
  6. raise error.RequestError(
  7. self.current_request_id, error.ERROR_DEVICE_NOT_FOUND
  8. )
  9. device_obj = device.obj
  10. device_status[device_id] = {
  11. "on": device_obj.is_on,
  12. "online": True,
  13. "brightness": round(device_obj.brightness * 100.0),
  14. "color": {"spectrumRGB": device_obj.color_rgb_spectrum},
  15. }
  16. return device_status

License

See LICENSE.