diff --git a/homeassistant/components/arwn/sensor.py b/homeassistant/components/arwn/sensor.py index 3db1283279e..18186e8b871 100644 --- a/homeassistant/components/arwn/sensor.py +++ b/homeassistant/components/arwn/sensor.py @@ -30,26 +30,30 @@ def discover_sensors(topic, payload): unit = TEMP_FAHRENHEIT else: unit = TEMP_CELSIUS - return ArwnSensor(name, "temp", unit) + return ArwnSensor(topic, name, "temp", unit) if domain == "moisture": name = f"{parts[2]} Moisture" - return ArwnSensor(name, "moisture", unit, "mdi:water-percent") + return ArwnSensor(topic, name, "moisture", unit, "mdi:water-percent") if domain == "rain": if len(parts) >= 3 and parts[2] == "today": return ArwnSensor( - "Rain Since Midnight", "since_midnight", "in", "mdi:water" + topic, "Rain Since Midnight", "since_midnight", "in", "mdi:water" ) return ( - ArwnSensor("Total Rainfall", "total", unit, "mdi:water"), - ArwnSensor("Rainfall Rate", "rate", unit, "mdi:water"), + ArwnSensor(topic + "/total", "Total Rainfall", "total", unit, "mdi:water"), + ArwnSensor(topic + "/rate", "Rainfall Rate", "rate", unit, "mdi:water"), ) if domain == "barometer": - return ArwnSensor("Barometer", "pressure", unit, "mdi:thermometer-lines") + return ArwnSensor(topic, "Barometer", "pressure", unit, "mdi:thermometer-lines") if domain == "wind": return ( - ArwnSensor("Wind Speed", "speed", unit, "mdi:speedometer"), - ArwnSensor("Wind Gust", "gust", unit, "mdi:speedometer"), - ArwnSensor("Wind Direction", "direction", DEGREE, "mdi:compass"), + ArwnSensor( + topic + "/speed", "Wind Speed", "speed", unit, "mdi:speedometer" + ), + ArwnSensor(topic + "/gust", "Wind Gust", "gust", unit, "mdi:speedometer"), + ArwnSensor( + topic + "/dir", "Wind Direction", "direction", DEGREE, "mdi:compass" + ), ) @@ -95,11 +99,15 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= sensor.set_event(event) store[sensor.name] = sensor _LOGGER.debug( - "Registering new sensor %(name)s => %(event)s", + "Registering sensor %(name)s => %(event)s", {"name": sensor.name, "event": event}, ) async_add_entities((sensor,), True) else: + _LOGGER.debug( + "Recording sensor %(name)s => %(event)s", + {"name": sensor.name, "event": event}, + ) store[sensor.name].set_event(event) await mqtt.async_subscribe(hass, TOPIC, async_sensor_event_received, 0) @@ -109,11 +117,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= class ArwnSensor(Entity): """Representation of an ARWN sensor.""" - def __init__(self, name, state_key, units, icon=None): + def __init__(self, topic, name, state_key, units, icon=None): """Initialize the sensor.""" self.hass = None self.entity_id = _slug(name) self._name = name + # This mqtt topic for the sensor which is its uid + self._uid = topic self._state_key = state_key self.event = {} self._unit_of_measurement = units @@ -135,6 +145,14 @@ class ArwnSensor(Entity): """Get the name of the sensor.""" return self._name + @property + def unique_id(self): + """Return a unique ID. + + This is based on the topic that comes from mqtt + """ + return self._uid + @property def state_attributes(self): """Return all the state attributes."""