Allow disabling device creation. Fix #31

This commit is contained in:
Thomas Lovén 2019-11-22 23:54:51 +01:00
parent 61d23a8136
commit 9fa91eec3c
5 changed files with 39 additions and 7 deletions

View File

@ -70,6 +70,24 @@ browser_mod:
```
This does not apply to devices with an alias.
### Disabling entities
`browser_mod` creates a number of entities, which is explained below. In some cases, you may not want to do that. If so, add a list of entity types you do *not* want to add to a `disable` section, either for each device, or globally to ignore for all unknown devices:
E.g. to disable the `light` and `media_player` for the device aliased to `arrakis`, AND disable *all* entities for all devices which *don't* have an alias:
```yaml
browser_mod:
devices:
99980b13-dabc9563:
name: arrakis
disable:
- light
- media_player
disable:
- all
````
## Entities
Once `browser_mod` is installed, loading up your Home Assistant frontend on a new *device* will create three to five new devices.

View File

@ -74,7 +74,8 @@ class BrowserModConnection:
'sensor',
self.deviceID,
self)
self.sensor.data = data.get('browser')
if self.sensor:
self.sensor.data = data.get('browser')
if data.get('player'):
self.media_player = self.media_player or create_entity(
@ -82,7 +83,8 @@ class BrowserModConnection:
'media_player',
self.deviceID,
self)
self.media_player.data = data.get('player')
if self.media_player:
self.media_player.data = data.get('player')
if data.get('screen'):
self.screen = self.screen or create_entity(
@ -90,7 +92,8 @@ class BrowserModConnection:
'light',
self.deviceID,
self)
self.screen.data = data.get('screen')
if self.screen:
self.screen.data = data.get('screen')
if data.get('fully'):
self.fully = self.fully or create_entity(
@ -98,7 +101,8 @@ class BrowserModConnection:
'binary_sensor',
self.deviceID,
self)
self.fully.data = data.get('fully')
if self.fully:
self.fully.data = data.get('fully')
if data.get('camera'):
self.camera = self.camera or create_entity(
@ -106,5 +110,6 @@ class BrowserModConnection:
'camera',
self.deviceID,
self)
self.camera.data = data.get('camera')
if self.camera:
self.camera.data = data.get('camera')

View File

@ -11,6 +11,8 @@ DATA_CONFIG = "config"
CONFIG_DEVICES = "devices"
CONFIG_PREFIX = "prefix"
CONFIG_DISABLE = "disable"
CONFIG_DISABLE_ALL = "all"
WS_ROOT = DOMAIN
WS_CONNECT = "{}/connect".format(WS_ROOT)

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, CONFIG_PREFIX
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES, DATA_ADDERS, CONFIG_DEVICES, DATA_CONFIG, CONFIG_PREFIX, CONFIG_DISABLE, CONFIG_DISABLE_ALL
_LOGGER = logging.getLogger(__name__)
@ -20,6 +20,13 @@ def get_config(hass, deviceID):
return config.get(deviceID, config.get(deviceID.replace('-','_'), {}))
def create_entity(hass, platform, deviceID, connection):
conf = get_config(hass, deviceID)
if conf and (platform in conf.get(CONFIG_DISABLE, [])
or CONFIG_DISABLE_ALL in conf.get(CONFIG_DISABLE, [])):
return None
if not conf and (platform in hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_DISABLE, [])
or CONFIG_DISABLE_ALL in hass.data[DOMAIN][DATA_CONFIG].get(CONFIG_DISABLE, [])):
return None
adder = hass.data[DOMAIN][DATA_ADDERS][platform]
entity = adder(hass, deviceID, connection, get_alias(hass, deviceID))
return entity

View File

@ -6,7 +6,7 @@
"scripts": {
"build": "webpack",
"watch": "webpack --watch --mode=development",
"test": "echo \"Error: no test specified\" && exit 1"
"update-card-tools": "npm uninstall card-tools && npm install thomasloven/lovelace-card-tools"
},
"keywords": [],
"author": "Thomas Lovén",