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

- some cleanup

- Added support for location in DB



git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@3053 b32b6428-25c9-4566-ad07-03861ab6144f
parent fa5a6b11
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
A bridge to provide access to xAAL Bus in Home-Assistant A bridge to provide access to xAAL Bus in Home-Assistant
## Important: ## Important:
- Don't use this in production! only for test right now
- Missing config entry: Right now, there is no configuration for this addon - Missing config entry: Right now, there is no configuration for this addon
- Integration on start: If you want to add a new device, you have to restart hass - Integration on start: If you want to add a new device, you have to restart hass
- Slow startup: The addon search for devices at startup, this can take some time. - Slow startup: The addon search for devices at startup, this can take some time.
......
...@@ -374,7 +374,7 @@ class Bridge(object): ...@@ -374,7 +374,7 @@ class Bridge(object):
_LOGGER.info(event.data) _LOGGER.info(event.data)
addrs = self.ident_to_address(dev_ident) addrs = self.ident_to_address(dev_ident)
kv = {'ha_dev_name': device_entry.name_by_user} kv = {'ha_dev_name': device_entry.name_by_user, 'location': device_entry.area_id}
for addr in addrs: for addr in addrs:
body = {'device': addr, 'map': kv} body = {'device': addr, 'map': kv}
self.ha_update_db(body) self.ha_update_db(body)
...@@ -396,9 +396,7 @@ class Bridge(object): ...@@ -396,9 +396,7 @@ class Bridge(object):
entity = self.get_entity_by_id(entity_id) entity = self.get_entity_by_id(entity_id)
if entity: if entity:
name = entity.registry_entry.name name = entity.registry_entry.name
if (name is None) and (entity._dev.db.get('ha_name') is None): if 'name' not in event.data.get('changes',{}).keys():
# HASS and DB can be out of sync, so we push db even if everything looks
# fine, except if there is no data
return return
kv = {'ha_name': name} kv = {'ha_name': name}
body = {'device': entity.address, 'map': kv} body = {'device': entity.address, 'map': kv}
......
...@@ -6,10 +6,11 @@ from homeassistant.core import HomeAssistant ...@@ -6,10 +6,11 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity, STATE_CLASS_MEASUREMENT from homeassistant.components.sensor import SensorDeviceClass, SensorEntity, STATE_CLASS_MEASUREMENT
from homeassistant import const from homeassistant import const
from homeassistant import util
from .bridge import XAALEntity, async_setup_factory from .bridge import XAALEntity, async_setup_factory
from .const import XAAL_TTS_SCHEMA from .const import XAAL_TTS_SCHEMA
from . import utils
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
...@@ -29,8 +30,7 @@ async def async_setup_entry(hass: HomeAssistant, ...@@ -29,8 +30,7 @@ async def async_setup_entry(hass: HomeAssistant,
'co2meter.' : [CO2Meter], 'co2meter.' : [CO2Meter],
'soundmeter.' : [SoundMeter], 'soundmeter.' : [SoundMeter],
'gateway.' : [Gateway], 'gateway.' : [Gateway],
'tts.' : [TTS], 'tts.' : [TTS], }
}
return async_setup_factory(hass, config_entry, async_add_entities, binding) return async_setup_factory(hass, config_entry, async_add_entities, binding)
...@@ -131,7 +131,7 @@ class TTS(XAALEntity): ...@@ -131,7 +131,7 @@ class TTS(XAALEntity):
_attr_native_value = 1 _attr_native_value = 1
def setup(self): def setup(self):
name = utils.str_to_id(self.name) name = util.slugify(self.name)
self._bridge.hass.services.async_register("notify", name, self.say, XAAL_TTS_SCHEMA) self._bridge.hass.services.async_register("notify", name, self.say, XAAL_TTS_SCHEMA)
def say(self, service): def say(self, service):
......
def str_to_id(value: str) -> str:
return value.translate ({ord(c): "_" for c in "!@#$%^&*()[]{};:,./<>?\|`~-=_+ "})
def get_dev_identifiers(identifiers: str) -> tuple[str, str]: def get_dev_identifiers(identifiers: str) -> tuple[str, str]:
ident_data = list(identifiers) ident_data = list(identifiers)
...@@ -8,4 +5,3 @@ def get_dev_identifiers(identifiers: str) -> tuple[str, str]: ...@@ -8,4 +5,3 @@ def get_dev_identifiers(identifiers: str) -> tuple[str, str]:
dev_ident = ident_data[0][1] dev_ident = ident_data[0][1]
return (domain, dev_ident) return (domain, dev_ident)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment