Skip to content

Commit

Permalink
Fix exception for devices who return JSON_ARRAY/JSON.OBJECT as state (#…
Browse files Browse the repository at this point in the history
…388)

* fix Datatype errors when get state #387

* Update coordinator.py

* fix style.

* fix typing

* Simplify the fix
  • Loading branch information
vlebourl authored Feb 17, 2021
1 parent 0612a5b commit 3c43f1f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions custom_components/tahoma/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Helpers to help coordinate updates."""
from datetime import timedelta
import json
import logging
from typing import Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Union

from aiohttp import ServerDisconnectedError
from homeassistant.core import HomeAssistant
Expand All @@ -24,6 +25,8 @@
DataType.STRING: str,
DataType.FLOAT: float,
DataType.BOOLEAN: bool,
DataType.JSON_ARRAY: json.loads,
DataType.JSON_OBJECT: json.loads,
}

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -143,7 +146,9 @@ async def _get_devices(self) -> Dict[str, Device]:
return {d.deviceurl: d for d in await self.client.get_devices(refresh=True)}

@staticmethod
def _get_state(state: State) -> Union[float, int, bool, str, None]:
def _get_state(
state: State,
) -> Union[Dict[Any, Any], List[Any], float, int, bool, str, None]:
"""Cast string value to the right type."""
if state.type != DataType.NONE:
caster = TYPES.get(DataType(state.type))
Expand Down

0 comments on commit 3c43f1f

Please sign in to comment.