mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Switch rest to use the json helper (#73867)
This commit is contained in:
parent
33c263d09b
commit
ab30d38469
@ -1,7 +1,6 @@
|
||||
"""Support for RESTful API sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
from xml.parsers.expat import ExpatError
|
||||
|
||||
@ -26,6 +25,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.json import json_dumps, json_loads
|
||||
from homeassistant.helpers.template_entity import TemplateSensor
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
@ -141,7 +141,7 @@ class RestSensor(BaseRestEntity, TemplateSensor):
|
||||
or content_type.startswith("application/rss+xml")
|
||||
):
|
||||
try:
|
||||
value = json.dumps(xmltodict.parse(value))
|
||||
value = json_dumps(xmltodict.parse(value))
|
||||
_LOGGER.debug("JSON converted from XML: %s", value)
|
||||
except ExpatError:
|
||||
_LOGGER.warning(
|
||||
@ -153,7 +153,7 @@ class RestSensor(BaseRestEntity, TemplateSensor):
|
||||
self._attributes = {}
|
||||
if value:
|
||||
try:
|
||||
json_dict = json.loads(value)
|
||||
json_dict = json_loads(value)
|
||||
if self._json_attrs_path is not None:
|
||||
json_dict = jsonpath(json_dict, self._json_attrs_path)
|
||||
# jsonpath will always store the result in json_dict[0]
|
||||
|
@ -86,4 +86,7 @@ def json_dumps(data: Any) -> str:
|
||||
).decode("utf-8")
|
||||
|
||||
|
||||
json_loads = orjson.loads
|
||||
|
||||
|
||||
JSON_DUMP: Final = json_dumps
|
||||
|
Loading…
x
Reference in New Issue
Block a user