初始化config文件
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
"""Helpers for node-red."""
|
||||
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.helpers.json import JSONEncoder
|
||||
|
||||
|
||||
class NodeRedJSONEncoder(JSONEncoder):
|
||||
"""JSONEncoder that supports timedelta objects and falls back to the Home Assistant Encoder."""
|
||||
|
||||
def default(self, o: Any) -> Any:
|
||||
"""Convert timedelta objects.
|
||||
|
||||
Hand other objects to the Home Assistant JSONEncoder.
|
||||
"""
|
||||
if isinstance(o, timedelta):
|
||||
return o.total_seconds()
|
||||
|
||||
return JSONEncoder.default(self, o)
|
||||
Reference in New Issue
Block a user