diff --git a/README.md b/README.md index e76a2df..374aff3 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/custom_components/browser_mod/connection.py b/custom_components/browser_mod/connection.py index 3368188..e56ab79 100644 --- a/custom_components/browser_mod/connection.py +++ b/custom_components/browser_mod/connection.py @@ -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') diff --git a/custom_components/browser_mod/const.py b/custom_components/browser_mod/const.py index 95c0897..b156c1f 100644 --- a/custom_components/browser_mod/const.py +++ b/custom_components/browser_mod/const.py @@ -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) diff --git a/custom_components/browser_mod/helpers.py b/custom_components/browser_mod/helpers.py index 5c30a2e..f533ac3 100644 --- a/custom_components/browser_mod/helpers.py +++ b/custom_components/browser_mod/helpers.py @@ -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 diff --git a/package.json b/package.json index c1a0746..d9c3db3 100644 --- a/package.json +++ b/package.json @@ -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",