Remove homeassistant.remote (#16099)

* Remove homeassistant.remote

* Use direct import for API

* Fix docstring
This commit is contained in:
Paulus Schoutsen
2018-08-21 15:49:58 +02:00
committed by GitHub
parent ae5c4c7e13
commit 7bb5344942
18 changed files with 62 additions and 555 deletions

View 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)