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

- Added support for shutter

- Fix wifimeter units



git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2991 b32b6428-25c9-4566-ad07-03861ab6144f
parent fb4b4132
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,7 @@ from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
PLATFORMS: list[str] = ["light", "switch", "sensor", "binary_sensor"]
PLATFORMS: list[str] = ["light", "switch", "sensor", "binary_sensor","cover"]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
......@@ -17,7 +17,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
bridge = Bridge(hass)
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = bridge
#await bridge.wait_is_ready()
# await bridge.wait_is_ready()
# _LOGGER.debug("xAAL Bridge READY")
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
return True
......
......@@ -87,6 +87,9 @@ class Bridge(object):
return False
def monitor_event(self, event, dev):
# DB_SERVER keep spamming us
if dev.address == DB_SERVER: return
entity = self.get_entity(dev.address)
#_LOGGER.debug(f"{event} {dev.address} {dev.is_ready()} => {entity}")
......
import logging
from typing import Any
from homeassistant.components.cover import CoverEntity, CoverDeviceClass, CoverEntityFeature, ATTR_POSITION
from .core import XAALEntity, EntityFactory, async_setup_factory
_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)
class Factory(EntityFactory):
def new_entity(self, device):
entity = None
if device.dev_type.startswith('shutter.basic'):
entity = Shutter(device, self._bridge)
if device.dev_type.startswith('shutter.position'):
entity = ShutterPosition(device, self._bridge)
if entity:
self.add_entity(entity,device.address)
return True
return False
class Shutter(XAALEntity, CoverEntity):
_attr_device_class= CoverDeviceClass.SHUTTER
@property
def supported_features(self) -> int:
supported_features = 0
supported_features |= (
CoverEntityFeature.OPEN
| CoverEntityFeature.CLOSE
| CoverEntityFeature.STOP
)
return supported_features
@property
def is_closed(self) -> bool | None:
return None
def open_cover(self, **kwargs: Any) -> None:
self.send_request('up')
def close_cover(self, **kwargs: Any) -> None:
self.send_request('down')
def stop_cover(self, **kwargs: Any) -> None:
self.send_request('stop')
class ShutterPosition(Shutter):
@property
def supported_features(self) -> int:
supported_features = 0
supported_features |= (
CoverEntityFeature.OPEN
| CoverEntityFeature.CLOSE
| CoverEntityFeature.STOP
| CoverEntityFeature.SET_POSITION
)
return supported_features
@property
def is_closed(self) -> bool | None:
if self._dev.attributes.get('position', None) == 0:
return True
return False
@property
def is_closing(self) -> bool | None:
if self._dev.attributes.get('action',None) == 'down':
return True
return False
@property
def is_opening(self) -> bool | None:
if self._dev.attributes.get('action',None) == 'up':
return True
return False
@property
def current_cover_position(self) -> int | None:
return self._dev.attributes.get('position',None)
def set_cover_position(self, **kwargs: Any) -> None:
position = kwargs.get(ATTR_POSITION, None)
if position:
self.send_request('set_position',{'position':position})
......@@ -76,6 +76,7 @@ class PowerMeter(XAALSensorEntity):
class WifiMeter(XAALSensorEntity):
_attr_device_class= SensorDeviceClass.SIGNAL_STRENGTH
_attr_native_unit_of_measurement = const.SIGNAL_STRENGTH_DECIBELS
_xaal_attribute = 'rssi'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment