Skip to content

Commit

Permalink
feat: use yaml to parse action params
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Dec 25, 2024
1 parent 365f4e5 commit f60143b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions custom_components/xiaomi_home/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@
Notify entities for Xiaomi Home.
"""
from __future__ import annotations
import json
import logging
from typing import Optional

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.notify import NotifyEntity
from homeassistant.util import yaml
from homeassistant.exceptions import HomeAssistantError

from .miot.miot_spec import MIoTSpecAction
from .miot.miot_device import MIoTDevice, MIoTActionEntity
Expand Down Expand Up @@ -103,13 +104,16 @@ async def async_send_message(
self.name, self.entity_id)
return
try:
in_list: list = json.loads(message)
except json.JSONDecodeError:
in_list: list = yaml.parse_yaml(message)
except HomeAssistantError:
_LOGGER.error(
'action exec failed, %s(%s), invalid action params format, %s',
self.name, self.entity_id, message)
return

if isinstance(in_list, str):
in_list = [in_list]

if not isinstance(in_list, list) or len(in_list) != len(self.spec.in_):
_LOGGER.error(
'action exec failed, %s(%s), invalid action params, %s',
Expand Down

0 comments on commit f60143b

Please sign in to comment.