mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add unique_id configuration variable to command_line integration (#58596)
This commit is contained in:
@@ -12,6 +12,7 @@ from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import (
|
||||
CONF_COMMAND,
|
||||
CONF_NAME,
|
||||
CONF_UNIQUE_ID,
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
CONF_VALUE_TEMPLATE,
|
||||
STATE_UNKNOWN,
|
||||
@@ -43,6 +44,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
|
||||
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -62,13 +64,19 @@ def setup_platform(
|
||||
unit = config.get(CONF_UNIT_OF_MEASUREMENT)
|
||||
value_template = config.get(CONF_VALUE_TEMPLATE)
|
||||
command_timeout = config.get(CONF_COMMAND_TIMEOUT)
|
||||
unique_id = config.get(CONF_UNIQUE_ID)
|
||||
if value_template is not None:
|
||||
value_template.hass = hass
|
||||
json_attributes = config.get(CONF_JSON_ATTRIBUTES)
|
||||
data = CommandSensorData(hass, command, command_timeout)
|
||||
|
||||
add_entities(
|
||||
[CommandSensor(hass, data, name, unit, value_template, json_attributes)], True
|
||||
[
|
||||
CommandSensor(
|
||||
hass, data, name, unit, value_template, json_attributes, unique_id
|
||||
)
|
||||
],
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
@@ -76,7 +84,14 @@ class CommandSensor(SensorEntity):
|
||||
"""Representation of a sensor that is using shell commands."""
|
||||
|
||||
def __init__(
|
||||
self, hass, data, name, unit_of_measurement, value_template, json_attributes
|
||||
self,
|
||||
hass,
|
||||
data,
|
||||
name,
|
||||
unit_of_measurement,
|
||||
value_template,
|
||||
json_attributes,
|
||||
unique_id,
|
||||
):
|
||||
"""Initialize the sensor."""
|
||||
self._hass = hass
|
||||
@@ -87,6 +102,7 @@ class CommandSensor(SensorEntity):
|
||||
self._state = None
|
||||
self._unit_of_measurement = unit_of_measurement
|
||||
self._value_template = value_template
|
||||
self._attr_unique_id = unique_id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
||||
Reference in New Issue
Block a user