From 66ab50c7371634ae4bd3d9eddd5a2da7764d10ae Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 19 Jan 2026 10:14:36 +0100 Subject: [PATCH] Fix incorrect device class in wirelesstag binary_sensor (#161215) --- .../components/wirelesstag/binary_sensor.py | 62 +++++-------------- 1 file changed, 16 insertions(+), 46 deletions(-) diff --git a/homeassistant/components/wirelesstag/binary_sensor.py b/homeassistant/components/wirelesstag/binary_sensor.py index eda9571f4b2..430c4c07bde 100644 --- a/homeassistant/components/wirelesstag/binary_sensor.py +++ b/homeassistant/components/wirelesstag/binary_sensor.py @@ -3,6 +3,7 @@ from __future__ import annotations import voluptuous as vol +from wirelesstagpy import SensorTag, constants as WT_CONSTANTS from homeassistant.components.binary_sensor import ( PLATFORM_SCHEMA as BINARY_SENSOR_PLATFORM_SCHEMA, @@ -16,53 +17,24 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType +from . import WirelessTagPlatform from .const import SIGNAL_BINARY_EVENT_UPDATE, WIRELESSTAG_DATA from .entity import WirelessTagBaseSensor from .util import async_migrate_unique_id -# On means in range, Off means out of range -SENSOR_PRESENCE = "presence" - -# On means motion detected, Off means clear -SENSOR_MOTION = "motion" - -# On means open, Off means closed -SENSOR_DOOR = "door" - -# On means temperature become too cold, Off means normal -SENSOR_COLD = "cold" - -# On means hot, Off means normal -SENSOR_HEAT = "heat" - -# On means too dry (humidity), Off means normal -SENSOR_DRY = "dry" - -# On means too wet (humidity), Off means normal -SENSOR_WET = "wet" - -# On means light detected, Off means no light -SENSOR_LIGHT = "light" - -# On means moisture detected (wet), Off means no moisture (dry) -SENSOR_MOISTURE = "moisture" - -# On means tag battery is low, Off means normal -SENSOR_BATTERY = "battery" - # Sensor types: Name, device_class, push notification type representing 'on', # attr to check SENSOR_TYPES = { - SENSOR_PRESENCE: "Presence", - SENSOR_MOTION: "Motion", - SENSOR_DOOR: "Door", - SENSOR_COLD: "Cold", - SENSOR_HEAT: "Heat", - SENSOR_DRY: "Too dry", - SENSOR_WET: "Too wet", - SENSOR_LIGHT: "Light", - SENSOR_MOISTURE: "Leak", - SENSOR_BATTERY: "Low Battery", + WT_CONSTANTS.EVENT_PRESENCE: BinarySensorDeviceClass.PRESENCE, + WT_CONSTANTS.EVENT_MOTION: BinarySensorDeviceClass.MOTION, + WT_CONSTANTS.EVENT_DOOR: BinarySensorDeviceClass.DOOR, + WT_CONSTANTS.EVENT_COLD: BinarySensorDeviceClass.COLD, + WT_CONSTANTS.EVENT_HEAT: BinarySensorDeviceClass.HEAT, + WT_CONSTANTS.EVENT_DRY: None, + WT_CONSTANTS.EVENT_WET: None, + WT_CONSTANTS.EVENT_LIGHT: BinarySensorDeviceClass.LIGHT, + WT_CONSTANTS.EVENT_MOISTURE: BinarySensorDeviceClass.MOISTURE, + WT_CONSTANTS.EVENT_BATTERY: BinarySensorDeviceClass.BATTERY, } @@ -99,11 +71,14 @@ async def async_setup_platform( class WirelessTagBinarySensor(WirelessTagBaseSensor, BinarySensorEntity): """A binary sensor implementation for WirelessTags.""" - def __init__(self, api, tag, sensor_type): + def __init__( + self, api: WirelessTagPlatform, tag: SensorTag, sensor_type: str + ) -> None: """Initialize a binary sensor for a Wireless Sensor Tags.""" super().__init__(api, tag) self._sensor_type = sensor_type self._name = f"{self._tag.name} {self.event.human_readable_name}" + self._attr_device_class = SENSOR_TYPES[sensor_type] self._attr_unique_id = f"{self._uuid}_{self._sensor_type}" async def async_added_to_hass(self) -> None: @@ -124,11 +99,6 @@ class WirelessTagBinarySensor(WirelessTagBaseSensor, BinarySensorEntity): """Return True if the binary sensor is on.""" return self._state == STATE_ON - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of the binary sensor.""" - return self._sensor_type - @property def event(self): """Binary event of tag."""