Use json_loads_object in arwn (#88611)

This commit is contained in:
epenet 2023-03-01 07:43:33 +01:00 committed by GitHub
parent 9fc6700c5a
commit 95dd62186e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,6 @@
"""Support for collecting data from the ARWN project.""" """Support for collecting data from the ARWN project."""
from __future__ import annotations from __future__ import annotations
import json
import logging import logging
from homeassistant.components import mqtt from homeassistant.components import mqtt
@ -11,6 +10,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import slugify from homeassistant.util import slugify
from homeassistant.util.json import json_loads_object
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -102,7 +102,7 @@ async def async_setup_platform(
"""Set up the ARWN platform.""" """Set up the ARWN platform."""
@callback @callback
def async_sensor_event_received(msg): def async_sensor_event_received(msg: mqtt.ReceiveMessage) -> None:
"""Process events as sensors. """Process events as sensors.
When a new event on our topic (arwn/#) is received we map it When a new event on our topic (arwn/#) is received we map it
@ -115,7 +115,7 @@ async def async_setup_platform(
This lets us dynamically incorporate sensors without any This lets us dynamically incorporate sensors without any
configuration on our side. configuration on our side.
""" """
event = json.loads(msg.payload) event = json_loads_object(msg.payload)
sensors = discover_sensors(msg.topic, event) sensors = discover_sensors(msg.topic, event)
if not sensors: if not sensors:
return return