Skip to content

Commit cb27f22

Browse files
pfefferleTony763
andauthored
show the latest snapshot of a camera connected to Home Assistant (#90)
* 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>
1 parent ebf5018 commit cb27f22

File tree

7 files changed

+48
-2
lines changed

7 files changed

+48
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Awaken your home - Control Home Assistant
44
## About
55
[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!
66

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

99
## Examples
1010
* "Turn on office light"

__init__.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ def _handle_client_exception(self, callback, *args, **kwargs):
199199
return False
200200

201201
# Intent handlers
202+
@intent_handler('show.camera.image.intent')
203+
def handle_show_camera_image_intent(self, message: Message) -> None:
204+
"""Handle show camera image intent."""
205+
message.data["Entity"] = message.data.get("entity")
206+
self._handle_camera_image_actions(message)
207+
202208
@intent_handler('turn.on.intent')
203209
def handle_turn_on_intent(self, message: Message) -> None:
204210
"""Handle turn on intent."""
@@ -305,6 +311,27 @@ def handle_shopping_list_intent(self, message: Message) -> None:
305311
message.data["Entity"] = message.data.get("entity")
306312
self._handle_shopping_list(message)
307313

314+
def _handle_camera_image_actions(self, message: Message) -> None:
315+
"""Handler for camera image actions."""
316+
entity = message.data["Entity"]
317+
318+
if not self.gui.connected:
319+
self.speak_dialog('homeassistant.error.no_gui')
320+
return
321+
322+
ha_entity = self._find_entity(entity, ['camera'])
323+
324+
if not ha_entity or not self._check_availability(ha_entity):
325+
return
326+
327+
attributes = ha_entity['attributes']
328+
entity_picture = attributes.get('entity_picture')
329+
330+
self.acknowledge()
331+
332+
self.gui.clear()
333+
self.gui.show_image(f"{self.ha_client.url}{entity_picture}", override_idle=15)
334+
308335
def _handle_turn_actions(self, message: Message) -> None:
309336
"""Handler for turn on/off and toggle actions."""
310337
self.log.debug("Starting Switch Intent")
@@ -492,7 +519,6 @@ def _handle_stop_actions(self, message):
492519
self.speak_dialog("homeassistant.device.stopped",
493520
data=ha_entity)
494521
return
495-
496522
return
497523

498524
def _handle_light_adjust(self, message: Message) -> None:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@allure.suite:behave
2+
Feature: camera
3+
Scenario: show image of missing entity
4+
Given an English speaking user
5+
When the user says "show me the latest picture of Albert Einstein"
6+
Then "skill-homeassistant" should not reply
7+
8+
Scenario: show image
9+
Given an English speaking user
10+
When the user says "show me the latest picture of Mycroft camera"
11+
Then "skill-homeassistant" should reply with dialog from "homeassistant.error.no_gui"

test/ci/HA/configuration.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,10 @@ climate:
112112
# 14_add_item_shopping_list.feature
113113
shopping_list:
114114

115+
camera:
116+
# 15_show_camera_image.feature
117+
- platform: generic
118+
name: "Mycroft camera"
119+
entity_picture: /image.jpg
120+
115121
automation: !include automations.yaml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(ukaž|zobraz) (mi|) (poslední|aktuální|) (fotku|snímek) (z|) {Entity}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zeig (mir|) (das|ein|) (letzte|aktuelle|letztes|aktuelles|) bild von {Entity}.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
show (me|) (the|a|an|) (latest|actual|) (picture|still|shot|snapshot) of {Entity}.

0 commit comments

Comments
 (0)