Skip to content

Commit

Permalink
Handle exceptions in execution of commands (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
iMicknl authored Sep 17, 2020
1 parent 39baced commit 7c58f9f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion custom_components/tahoma/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/tahoma",
"requirements": [
"pyhoma==0.4.2"
"pyhoma==0.4.3"
],
"codeowners": ["@philklei", "@imicknl", "@vlebourl", "@tetienne"],
"issue_tracker": "https://github.com/imicknl/ha-tahoma/issues"
Expand Down
17 changes: 13 additions & 4 deletions custom_components/tahoma/tahoma_device.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Parent class for every TaHoma devices."""
"""Parent class for every TaHoma device."""
import logging
from typing import Any, Dict, Optional

from pyhoma.models import Command, Device
Expand All @@ -24,6 +25,8 @@
STATE_BATTERY_VERY_LOW = "verylow"
STATE_DEAD = "dead"

_LOGGER = logging.getLogger(__name__)


class TahomaDevice(Entity):
"""Representation of a TaHoma device entity."""
Expand Down Expand Up @@ -152,9 +155,15 @@ def has_state(self, *states: str) -> bool:

async def async_execute_command(self, command_name: str, *args: Any):
"""Execute device command in async context."""
exec_id = await self.coordinator.client.execute_command(
self.device.deviceurl, Command(command_name, list(args)), "Home Assistant"
)
try:
exec_id = await self.coordinator.client.execute_command(
self.device.deviceurl,
Command(command_name, list(args)),
"Home Assistant",
)
except Exception as exception:
_LOGGER.error(exception)
return

# ExecutionRegisteredEvent doesn't contain the deviceurl, thus we need to register it here
self.coordinator.executions[exec_id] = {
Expand Down
2 changes: 1 addition & 1 deletion requirements.test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pytest-cov<3.0.0
pytest-homeassistant

# from our manifest.json for our Custom Component
pyhoma==0.4.2
pyhoma==0.4.3

0 comments on commit 7c58f9f

Please sign in to comment.