Skip to content
Snippets Groups Projects
Commit 0a2f99f0 authored by jkerdreu's avatar jkerdreu
Browse files

- Cleanup

- Doc

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@3022 b32b6428-25c9-4566-ad07-03861ab6144f
parent 21978071
Branches
No related tags found
No related merge requests found
......@@ -24,15 +24,27 @@ UNSUPPORTED_TYPES = ['cli','hmi','windgauge',]
class XAALEntity(Entity):
#_attr_has_entity_name = True
_attr_available: bool = False
_attr_should_poll: bool = False
def __init__(self, dev: MonitorDevice, bridge: "Bridge") -> None:
self._dev = dev
self._bridge = bridge
self.setup()
#####################################################
# Init
#####################################################
def setup(self):
""" Use setup to tweak a entity at creation """
pass
async def async_added_to_hass(self) -> None:
"""call by HASS when entity is ready"""
self._attr_available = True
#####################################################
# HASS Device
#####################################################
@property
def device_info(self) -> DeviceInfo | None :
dev = self._dev
......@@ -52,6 +64,9 @@ class XAALEntity(Entity):
"suggested_area" : dev.db.get("location",None)
}
#####################################################
# xAAL helpers
#####################################################
def send_request(self, action: str, body: Dict[str, Any] | None =None) -> None:
_LOGGER.debug(f"{self} {action} {body}")
self._bridge.send_request([self._dev.address, ], action, body)
......@@ -60,17 +75,15 @@ class XAALEntity(Entity):
""" return a attribute for xAAL device"""
return self._dev.attributes.get(name, default)
#####################################################
# Entity properties
#####################################################
def short_type(self) -> str:
""" return a fake device class for entity that doesn't have one """
# this apply for light, button
# NOTE: I don't know why some entities don't have a device class
return self._dev.dev_type.split('.')[0]
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False
@property
def name(self) -> str | None:
force_name = getattr(self,'_force_name',None)
......@@ -83,10 +96,6 @@ class XAALEntity(Entity):
if hasattr(self,'_xaal_attribute'):
return f"xaal.{addr}.{self._xaal_attribute}"
return f"xaal.{addr}"
async def async_added_to_hass(self) -> None:
"""call by HASS when entity is ready"""
self._attr_available = True
class EntityFactory(object):
......@@ -112,7 +121,6 @@ class EntityFactory(object):
return False
def async_setup_factory(
hass: HomeAssistant,
config_entry: ConfigEntry,
......@@ -152,10 +160,6 @@ class Bridge(object):
#####################################################
# Engine & Hooks
#####################################################
@property
def engine(self) -> AsyncEngine:
return self._eng
async def on_start(self) -> None:
"""Subscribe to Monitor events and Messages"""
#await self.wait_is_ready()
......@@ -238,7 +242,7 @@ class Bridge(object):
def send_request(self, targets: List[bindings.UUID], action: str, body: Dict[str, Any] | None =None):
"""send a xAAL request (queueing it)"""
self._mon.engine.send_request(self._dev, targets, action, body)
self._eng.send_request(self._dev, targets, action, body)
#####################################################
# Monitor events & callbacks
......
import voluptuous as vol
from homeassistant import config_entries
import logging
import voluptuous as vol
from homeassistant import config_entries
from .const import DOMAIN, CONF_DB_SERVER
_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema(
......@@ -24,7 +25,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
# no user input right now, so we just show the empty form
errors = {}
# if we have some user_input let's start
if user_input is not None:
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment