Python client for the Baby Tracker sync server, reverse engineered from the Android app (4.53), and a HACS-installable Home Assistant integration built on it. Each baby gets a log calendar and summary sensors, and actions add entries that sync back to the group. Reading has been run against the real server. Uploading and running inside real Home Assistant have not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
import asyncio
|
|
from dataclasses import dataclass, field
|
|
from enum import Enum
|
|
from typing import Any, Optional
|
|
|
|
ServiceResponse = Optional[dict]
|
|
|
|
|
|
def callback(func):
|
|
return func
|
|
|
|
|
|
class SupportsResponse(Enum):
|
|
NONE = "none"
|
|
OPTIONAL = "optional"
|
|
ONLY = "only"
|
|
|
|
|
|
@dataclass
|
|
class ServiceCall:
|
|
data: dict = field(default_factory=dict)
|
|
return_response: bool = False
|
|
|
|
|
|
class _Services:
|
|
def __init__(self):
|
|
self.registered = {}
|
|
|
|
def async_register(self, domain, service, handler, schema=None, supports_response=SupportsResponse.NONE):
|
|
self.registered[(domain, service)] = (handler, schema, supports_response)
|
|
|
|
async def async_call(self, domain, service, data=None, return_response=False):
|
|
handler, schema, _ = self.registered[(domain, service)]
|
|
validated = schema(dict(data or {})) if schema else dict(data or {})
|
|
return await handler(ServiceCall(validated, return_response))
|
|
|
|
|
|
class _Config:
|
|
def __init__(self, units):
|
|
self.units = units
|
|
|
|
|
|
class HomeAssistant:
|
|
def __init__(self, units):
|
|
self.config = _Config(units)
|
|
self.services = _Services()
|
|
self.config_entries = None
|
|
|
|
async def async_add_executor_job(self, target, *args):
|
|
return await asyncio.get_running_loop().run_in_executor(None, target, *args)
|