mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Enable sensor for discovery (#5974)
* Enable sensor for discovery * Remove blank line
This commit is contained in:
parent
462b47c725
commit
f82ac0af60
@ -20,7 +20,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
TOPIC_MATCHER = re.compile(
|
TOPIC_MATCHER = re.compile(
|
||||||
r'homeassistant/(?P<component>\w+)/(?P<object_id>\w+)/config')
|
r'homeassistant/(?P<component>\w+)/(?P<object_id>\w+)/config')
|
||||||
SUPPORTED_COMPONENTS = ['binary_sensor']
|
|
||||||
|
SUPPORTED_COMPONENTS = ['binary_sensor', 'sensor']
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -39,8 +40,7 @@ def async_start(hass, discovery_topic, hass_config):
|
|||||||
try:
|
try:
|
||||||
payload = json.loads(payload)
|
payload = json.loads(payload)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning("Unable to parse JSON %s: %s", object_id, payload)
|
||||||
"Unable to parse JSON %s: %s", object_id, payload)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if component not in SUPPORTED_COMPONENTS:
|
if component not in SUPPORTED_COMPONENTS:
|
||||||
|
@ -30,6 +30,9 @@ PLATFORM_SCHEMA = mqtt.MQTT_RO_PLATFORM_SCHEMA.extend({
|
|||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up MQTT Sensor."""
|
"""Set up MQTT Sensor."""
|
||||||
|
if discovery_info is not None:
|
||||||
|
config = PLATFORM_SCHEMA(discovery_info)
|
||||||
|
|
||||||
value_template = config.get(CONF_VALUE_TEMPLATE)
|
value_template = config.get(CONF_VALUE_TEMPLATE)
|
||||||
if value_template is not None:
|
if value_template is not None:
|
||||||
value_template.hass = hass
|
value_template.hass = hass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user