Skip to content

Commit

Permalink
show the latest snapshot of a camera connected to Home Assistant (#90)
Browse files Browse the repository at this point in the history
* initial

* fix URL

* make "me" optional

* use `override_idle` param instead of sleep

* play sound if picture found, if gui connected or not

* error if screen is not connected

* Add czech translation

* image shouldn't be optional

* remove brackets

* fix linter errors

* fix indents

* more concrete and descriptive namings

* renamed handler function to be more concrete

* add behave tests

* fix pylint error

* add workflow fixes

added by @Tony763

* fix indent issues

* revert change, I thought might fix pylint errors

* added type annotations

#90 (comment)

Co-authored-by: Antonín Skala <skala.antonin@gmail.com>
  • Loading branch information
pfefferle and Tony763 authored Mar 22, 2022
1 parent ebf5018 commit cb27f22
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Awaken your home - Control Home Assistant
## About
[Home Assistant](https://www.home-assistant.io/) lets you control all your smart devices in a single easy to use interface. This skill uses the open source Home Assistant's APIs to control devices and entities. Control your lights, garage door, thermostats and more using your voice!

Currently the following entity types are supported: `light`, `switch`, `scene`, `climate`, `groups`, `input_boolean`, `binary_sensor` and `cover`
Currently the following entity types are supported: `light`, `switch`, `scene`, `climate`, `groups`, `input_boolean`, `binary_sensor`, `cover` and `camera`

## Examples
* "Turn on office light"
Expand Down
28 changes: 27 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ def _handle_client_exception(self, callback, *args, **kwargs):
return False

# Intent handlers
@intent_handler('show.camera.image.intent')
def handle_show_camera_image_intent(self, message: Message) -> None:
"""Handle show camera image intent."""
message.data["Entity"] = message.data.get("entity")
self._handle_camera_image_actions(message)

@intent_handler('turn.on.intent')
def handle_turn_on_intent(self, message: Message) -> None:
"""Handle turn on intent."""
Expand Down Expand Up @@ -305,6 +311,27 @@ def handle_shopping_list_intent(self, message: Message) -> None:
message.data["Entity"] = message.data.get("entity")
self._handle_shopping_list(message)

def _handle_camera_image_actions(self, message: Message) -> None:
"""Handler for camera image actions."""
entity = message.data["Entity"]

if not self.gui.connected:
self.speak_dialog('homeassistant.error.no_gui')
return

ha_entity = self._find_entity(entity, ['camera'])

if not ha_entity or not self._check_availability(ha_entity):
return

attributes = ha_entity['attributes']
entity_picture = attributes.get('entity_picture')

self.acknowledge()

self.gui.clear()
self.gui.show_image(f"{self.ha_client.url}{entity_picture}", override_idle=15)

def _handle_turn_actions(self, message: Message) -> None:
"""Handler for turn on/off and toggle actions."""
self.log.debug("Starting Switch Intent")
Expand Down Expand Up @@ -492,7 +519,6 @@ def _handle_stop_actions(self, message):
self.speak_dialog("homeassistant.device.stopped",
data=ha_entity)
return

return

def _handle_light_adjust(self, message: Message) -> None:
Expand Down
11 changes: 11 additions & 0 deletions test/behave/15_show_camera_image.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@allure.suite:behave
Feature: camera
Scenario: show image of missing entity
Given an English speaking user
When the user says "show me the latest picture of Albert Einstein"
Then "skill-homeassistant" should not reply

Scenario: show image
Given an English speaking user
When the user says "show me the latest picture of Mycroft camera"
Then "skill-homeassistant" should reply with dialog from "homeassistant.error.no_gui"
6 changes: 6 additions & 0 deletions test/ci/HA/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,10 @@ climate:
# 14_add_item_shopping_list.feature
shopping_list:

camera:
# 15_show_camera_image.feature
- platform: generic
name: "Mycroft camera"
entity_picture: /image.jpg

automation: !include automations.yaml
1 change: 1 addition & 0 deletions vocab/cs-cz/show.camera.image.intent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ukaž|zobraz) (mi|) (poslední|aktuální|) (fotku|snímek) (z|) {Entity}
1 change: 1 addition & 0 deletions vocab/de-de/show.camera.image.intent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zeig (mir|) (das|ein|) (letzte|aktuelle|letztes|aktuelles|) bild von {Entity}.
1 change: 1 addition & 0 deletions vocab/en-us/show.camera.image.intent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
show (me|) (the|a|an|) (latest|actual|) (picture|still|shot|snapshot) of {Entity}.

0 comments on commit cb27f22

Please sign in to comment.