Add sensor name prefix. Fix #20. Add Toast command
This commit is contained in:
parent
98f2797aa1
commit
eaed9cd8d9
20
README.md
20
README.md
@ -60,6 +60,16 @@ This binds the *aliases* `arrakis` to `99980b13-dabc9563` and `dashboard` to `d2
|
||||
|
||||
Note: Aliases must be unique.
|
||||
|
||||
### Prefix
|
||||
You can add a custom prefix to all entity ids in `configuration.yaml`:
|
||||
|
||||
E.g. to give entities default names like `media_player.browser_99980b13_dabc9563` add:
|
||||
```yaml
|
||||
browser_mod:
|
||||
prefix: "browser_"
|
||||
```
|
||||
This does not apply to devices with an alias.
|
||||
|
||||
## Entities
|
||||
Once `browser_mod` is installed, loading up your Home Assistant frontend on a new *device* will create three to five new devices.
|
||||
|
||||
@ -185,6 +195,16 @@ will show the more-info dialog of `camera.front_door` on the *devices* `ded3b4dc
|
||||
|
||||
The optional parameter `large: true` will make the popup wider.
|
||||
|
||||
### toast
|
||||
```
|
||||
service: browser_mod.toast
|
||||
service_data:
|
||||
message: Short message
|
||||
```
|
||||
|
||||
Display a toast notification on all devices.
|
||||
The optional parameter `duration:` determines the time (in ms) that the toast is shown. Set to 0 for persistent display. Default is 3000.
|
||||
|
||||
### popup
|
||||
```
|
||||
service: browser_mod.popup
|
||||
|
@ -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
@ -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",
|
||||
]
|
||||
|
@ -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
|
||||
|
12
js/main.js
12
js/main.js
@ -126,6 +126,9 @@ class BrowserMod {
|
||||
this.mute(msg);
|
||||
break;
|
||||
|
||||
case "toast":
|
||||
this.toast(msg);
|
||||
break;
|
||||
case "popup":
|
||||
this.popup(msg);
|
||||
break;
|
||||
@ -208,6 +211,15 @@ class BrowserMod {
|
||||
this.player.muted = Boolean(msg.mute)
|
||||
}
|
||||
|
||||
toast(msg) {
|
||||
if(!msg.message) return;
|
||||
|
||||
fireEvent("hass-notification", {
|
||||
message: msg.message,
|
||||
duration: msg.duration !== undefined ? parseInt(msg.duration) : undefined
|
||||
}, document.querySelector("home-assistant"));
|
||||
}
|
||||
|
||||
popup(msg){
|
||||
if(!msg.title && !msg.auto_close) return;
|
||||
if(!msg.card) return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user