Allow disabling device creation. Fix #31
This commit is contained in:
@@ -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')
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user