Allow disabling device creation. Fix #31
This commit is contained in:
parent
61d23a8136
commit
9fa91eec3c
18
README.md
18
README.md
@ -70,6 +70,24 @@ browser_mod:
|
|||||||
```
|
```
|
||||||
This does not apply to devices with an alias.
|
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
|
## Entities
|
||||||
Once `browser_mod` is installed, loading up your Home Assistant frontend on a new *device* will create three to five new devices.
|
Once `browser_mod` is installed, loading up your Home Assistant frontend on a new *device* will create three to five new devices.
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@ class BrowserModConnection:
|
|||||||
'sensor',
|
'sensor',
|
||||||
self.deviceID,
|
self.deviceID,
|
||||||
self)
|
self)
|
||||||
|
if self.sensor:
|
||||||
self.sensor.data = data.get('browser')
|
self.sensor.data = data.get('browser')
|
||||||
|
|
||||||
if data.get('player'):
|
if data.get('player'):
|
||||||
@ -82,6 +83,7 @@ class BrowserModConnection:
|
|||||||
'media_player',
|
'media_player',
|
||||||
self.deviceID,
|
self.deviceID,
|
||||||
self)
|
self)
|
||||||
|
if self.media_player:
|
||||||
self.media_player.data = data.get('player')
|
self.media_player.data = data.get('player')
|
||||||
|
|
||||||
if data.get('screen'):
|
if data.get('screen'):
|
||||||
@ -90,6 +92,7 @@ class BrowserModConnection:
|
|||||||
'light',
|
'light',
|
||||||
self.deviceID,
|
self.deviceID,
|
||||||
self)
|
self)
|
||||||
|
if self.screen:
|
||||||
self.screen.data = data.get('screen')
|
self.screen.data = data.get('screen')
|
||||||
|
|
||||||
if data.get('fully'):
|
if data.get('fully'):
|
||||||
@ -98,6 +101,7 @@ class BrowserModConnection:
|
|||||||
'binary_sensor',
|
'binary_sensor',
|
||||||
self.deviceID,
|
self.deviceID,
|
||||||
self)
|
self)
|
||||||
|
if self.fully:
|
||||||
self.fully.data = data.get('fully')
|
self.fully.data = data.get('fully')
|
||||||
|
|
||||||
if data.get('camera'):
|
if data.get('camera'):
|
||||||
@ -106,5 +110,6 @@ class BrowserModConnection:
|
|||||||
'camera',
|
'camera',
|
||||||
self.deviceID,
|
self.deviceID,
|
||||||
self)
|
self)
|
||||||
|
if self.camera:
|
||||||
self.camera.data = data.get('camera')
|
self.camera.data = data.get('camera')
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ DATA_CONFIG = "config"
|
|||||||
|
|
||||||
CONFIG_DEVICES = "devices"
|
CONFIG_DEVICES = "devices"
|
||||||
CONFIG_PREFIX = "prefix"
|
CONFIG_PREFIX = "prefix"
|
||||||
|
CONFIG_DISABLE = "disable"
|
||||||
|
CONFIG_DISABLE_ALL = "all"
|
||||||
|
|
||||||
WS_ROOT = DOMAIN
|
WS_ROOT = DOMAIN
|
||||||
WS_CONNECT = "{}/connect".format(WS_ROOT)
|
WS_CONNECT = "{}/connect".format(WS_ROOT)
|
||||||
|
@ -2,7 +2,7 @@ import logging
|
|||||||
|
|
||||||
from homeassistant.helpers.entity import Entity, async_generate_entity_id
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -20,6 +20,13 @@ def get_config(hass, deviceID):
|
|||||||
return config.get(deviceID, config.get(deviceID.replace('-','_'), {}))
|
return config.get(deviceID, config.get(deviceID.replace('-','_'), {}))
|
||||||
|
|
||||||
def create_entity(hass, platform, deviceID, connection):
|
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]
|
adder = hass.data[DOMAIN][DATA_ADDERS][platform]
|
||||||
entity = adder(hass, deviceID, connection, get_alias(hass, deviceID))
|
entity = adder(hass, deviceID, connection, get_alias(hass, deviceID))
|
||||||
return entity
|
return entity
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack",
|
"build": "webpack",
|
||||||
"watch": "webpack --watch --mode=development",
|
"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": [],
|
"keywords": [],
|
||||||
"author": "Thomas Lovén",
|
"author": "Thomas Lovén",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user