Add sensor name prefix. Fix #20. Add Toast command

This commit is contained in:
2019-10-03 15:26:54 +02:00
parent 98f2797aa1
commit eaed9cd8d9
6 changed files with 40 additions and 5 deletions

View File

@@ -22,7 +22,7 @@ async def async_setup(hass, config):
DATA_DEVICES: {},
DATA_ALIASES: aliases,
DATA_ADDERS: {},
DATA_CONFIG: config[DOMAIN].get(CONFIG_DEVICES, {}),
DATA_CONFIG: config[DOMAIN],
}
await hass.helpers.discovery.async_load_platform("media_player", DOMAIN, {}, config)

File diff suppressed because one or more lines are too long

View File

@@ -10,6 +10,7 @@ DATA_ADDERS = "adders"
DATA_CONFIG = "config"
CONFIG_DEVICES = "devices"
CONFIG_PREFIX = "prefix"
WS_ROOT = DOMAIN
WS_CONNECT = "{}/connect".format(WS_ROOT)
@@ -26,4 +27,5 @@ USER_COMMANDS = [
"lovelace-reload",
"blackout",
"no-blackout",
"toast",
]

View File

@@ -2,7 +2,7 @@ import logging
from homeassistant.helpers.entity import Entity, async_generate_entity_id
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES, DATA_ADDERS, CONFIG_DEVICES, DATA_CONFIG
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES, DATA_ADDERS, CONFIG_DEVICES, DATA_CONFIG, CONFIG_PREFIX
_LOGGER = logging.getLogger(__name__)
@@ -16,7 +16,7 @@ def get_alias(hass, deviceID):
return None
def get_config(hass, deviceID):
config = hass.data[DOMAIN][DATA_CONFIG]
config = hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_DEVICES, {})
return config.get(deviceID, config.get(deviceID.replace('-','_'), {}))
def create_entity(hass, platform, deviceID, connection):
@@ -39,7 +39,8 @@ class BrowserModEntity(Entity):
self.connection = connection
self.deviceID = deviceID
self._data = {}
self.entity_id = async_generate_entity_id(self.domain+".{}", alias or deviceID, hass=hass)
prefix = hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_PREFIX, '')
self.entity_id = async_generate_entity_id(self.domain+".{}", alias or f"{prefix}{deviceID}", hass=hass)
def updated(self):
pass