mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Remove homeassistant.remote (#16099)
* Remove homeassistant.remote * Use direct import for API * Fix docstring
This commit is contained in:
27
homeassistant/helpers/json.py
Normal file
27
homeassistant/helpers/json.py
Normal file
@ -0,0 +1,27 @@
|
||||
"""Helpers to help with encoding Home Assistant objects in JSON."""
|
||||
from datetime import datetime
|
||||
import json
|
||||
import logging
|
||||
|
||||
from typing import Any
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
"""JSONEncoder that supports Home Assistant objects."""
|
||||
|
||||
# pylint: disable=method-hidden
|
||||
def default(self, o: Any) -> Any:
|
||||
"""Convert Home Assistant objects.
|
||||
|
||||
Hand other objects to the original method.
|
||||
"""
|
||||
if isinstance(o, datetime):
|
||||
return o.isoformat()
|
||||
if isinstance(o, set):
|
||||
return list(o)
|
||||
if hasattr(o, 'as_dict'):
|
||||
return o.as_dict()
|
||||
|
||||
return json.JSONEncoder.default(self, o)
|
Reference in New Issue
Block a user