Remove homeassistant.remote (#16099)
* Remove homeassistant.remote * Use direct import for API * Fix docstring
This commit is contained in:
parent
ae5c4c7e13
commit
7bb5344942
18 changed files with 62 additions and 555 deletions
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)
|
Loading…
Add table
Add a link
Reference in a new issue