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

- Added async_setup_entry type ckeck

- Fix circular import on Bridge / core..

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2998 b32b6428-25c9-4566-ad07-03861ab6144f
parent 247705f9
Branches
No related tags found
No related merge requests found
......@@ -3,6 +3,9 @@ import logging
from typing import Literal
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.binary_sensor import BinarySensorEntity, BinarySensorDeviceClass
from homeassistant.const import STATE_ON, STATE_OFF
......@@ -11,9 +14,13 @@ from xaal.lib import Message
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
return async_setup_factory(hass, config_entry, async_add_entities, Factory)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
return async_setup_factory(hass, config_entry, async_add_entities, Factory)
class Factory(EntityFactory):
......
import logging
from typing import Any, Callable, Dict
from typing import Any, Callable, Dict, TYPE_CHECKING
from .const import DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.entity import Entity, DeviceInfo
from xaal.lib import bindings
from xaal.monitor.monitor import Device as MonitorDevice
if TYPE_CHECKING:
# Bridge import for type check produce a circular import
# error, to avoid this we use this trick.
from .bridge import Bridge
import logging
_LOGGER = logging.getLogger(__name__)
_LOGGER = logging.getLogger(__name__)
class XAALEntity(Entity):
# _attr_has_entity_name = True
def __init__(self, dev: MonitorDevice, bridge: Bridge) -> None:
def __init__(self, dev: MonitorDevice, bridge: "Bridge") -> None:
self._dev = dev
self._bridge = bridge
......@@ -74,7 +82,7 @@ class XAALEntity(Entity):
class EntityFactory(object):
def __init__(self, bridge: Bridge, async_add_entitites: Callable) -> None:
def __init__(self, bridge: "Bridge", async_add_entitites: Callable) -> None:
self._bridge = bridge
self._async_add_entitites = async_add_entitites
self._bridge.add_factory(self)
......@@ -85,7 +93,13 @@ class EntityFactory(object):
self._bridge.add_entity(address, entity)
def async_setup_factory(hass, config_entry, async_add_entities, factory_class):
def async_setup_factory(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
factory_class: EntityFactory
) -> None:
bridge = hass.data[DOMAIN][config_entry.entry_id]
factory = factory_class(bridge, async_add_entities)
for dev in bridge._mon.devices:
......
import logging
from typing import Any
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.cover import CoverEntity, CoverDeviceClass, CoverEntityFeature, ATTR_POSITION
from .core import XAALEntity, EntityFactory, MonitorDevice, async_setup_factory
......@@ -8,7 +11,11 @@ from .core import XAALEntity, EntityFactory, MonitorDevice, async_setup_factory
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
return async_setup_factory(hass, config_entry, async_add_entities, Factory)
......
import logging
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_COLOR_TEMP, LightEntity, ColorMode
from homeassistant.util import color as color_util
......@@ -8,7 +11,11 @@ from .core import XAALEntity, EntityFactory, MonitorDevice, async_setup_factory
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
return async_setup_factory(hass, config_entry, async_add_entities, Factory)
......
import logging
from typing import Any
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant import const
......@@ -8,8 +11,11 @@ from .core import XAALEntity, EntityFactory, MonitorDevice, async_setup_factory
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
return async_setup_factory(hass, config_entry, async_add_entities, Factory)
......
import logging
from homeassistant.components.switch import SwitchEntity, DEVICE_CLASS_OUTLET
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.switch import SwitchEntity, DEVICE_CLASS_OUTLET
from .core import EntityFactory, XAALEntity, MonitorDevice, async_setup_factory
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
return async_setup_factory(hass, config_entry, async_add_entities, Factory)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment