From 2b07c6f1a62f7a5a5bb4b8ca39d3213db179efb3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 4 May 2022 14:43:07 -0500 Subject: [PATCH] Fix lutron_caseta occupancy sensors --- .../components/lutron_caseta/__init__.py | 8 ++--- .../components/lutron_caseta/binary_sensor.py | 32 ++++++++++++------- .../components/lutron_caseta/const.py | 2 ++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/lutron_caseta/__init__.py b/homeassistant/components/lutron_caseta/__init__.py index b73d5178a15..3d9e07519a8 100644 --- a/homeassistant/components/lutron_caseta/__init__.py +++ b/homeassistant/components/lutron_caseta/__init__.py @@ -38,6 +38,7 @@ from .const import ( CONF_CA_CERTS, CONF_CERTFILE, CONF_KEYFILE, + CONFIG_URL, DOMAIN, LUTRON_CASETA_BUTTON_EVENT, MANUFACTURER, @@ -307,11 +308,6 @@ class LutronCasetaDevice(Entity): self._smartbridge = bridge self._bridge_device = bridge_device if "serial" not in self._device: - # - # Occupancy sensors do not have - # a unique serial since all of the ones - # in the same room are grouped together - # return info = DeviceInfo( identifiers={(DOMAIN, self.serial)}, @@ -319,7 +315,7 @@ class LutronCasetaDevice(Entity): model=f"{device['model']} ({device['type']})", name=self.name, via_device=(DOMAIN, self._bridge_device["serial"]), - configuration_url="https://device-login.lutron.com", + configuration_url=CONFIG_URL, ) area, _ = _area_and_name_from_name(device["name"]) if area != UNASSIGNED_AREA: diff --git a/homeassistant/components/lutron_caseta/binary_sensor.py b/homeassistant/components/lutron_caseta/binary_sensor.py index 788702f9353..aff19bdc71c 100644 --- a/homeassistant/components/lutron_caseta/binary_sensor.py +++ b/homeassistant/components/lutron_caseta/binary_sensor.py @@ -6,11 +6,13 @@ from homeassistant.components.binary_sensor import ( BinarySensorEntity, ) from homeassistant.config_entries import ConfigEntry +from homeassistant.const import ATTR_SUGGESTED_AREA from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import DOMAIN as CASETA_DOMAIN, LutronCasetaDevice -from .const import BRIDGE_DEVICE, BRIDGE_LEAP +from . import DOMAIN as CASETA_DOMAIN, LutronCasetaDevice, _area_and_name_from_name +from .const import BRIDGE_DEVICE, BRIDGE_LEAP, CONFIG_URL, MANUFACTURER, UNASSIGNED_AREA async def async_setup_entry( @@ -39,6 +41,22 @@ async def async_setup_entry( class LutronOccupancySensor(LutronCasetaDevice, BinarySensorEntity): """Representation of a Lutron occupancy group.""" + def __init__(self, device, bridge, bridge_device): + """Init an occupancy sensor.""" + super().__init__(device, bridge, bridge_device) + info = DeviceInfo( + identifiers={(CASETA_DOMAIN, self.unique_id)}, + manufacturer=MANUFACTURER, + model=f"{device['model']} ({device['type']})", + name=self.name, + via_device=(CASETA_DOMAIN, self._bridge_device["serial"]), + configuration_url=CONFIG_URL, + ) + area, _ = _area_and_name_from_name(device["name"]) + if area != UNASSIGNED_AREA: + info[ATTR_SUGGESTED_AREA] = area + self._attr_device_info = info + @property def device_class(self): """Flag supported features.""" @@ -65,16 +83,6 @@ class LutronOccupancySensor(LutronCasetaDevice, BinarySensorEntity): """Return a unique identifier.""" return f"occupancygroup_{self.device_id}" - @property - def device_info(self): - """Return the device info. - - Sensor entities are aggregated from one or more physical - sensors by each room. Therefore, there shouldn't be devices - related to any sensor entities. - """ - return None - @property def extra_state_attributes(self): """Return the state attributes.""" diff --git a/homeassistant/components/lutron_caseta/const.py b/homeassistant/components/lutron_caseta/const.py index 56a3821dd64..71d686ba2c8 100644 --- a/homeassistant/components/lutron_caseta/const.py +++ b/homeassistant/components/lutron_caseta/const.py @@ -35,3 +35,5 @@ CONF_SUBTYPE = "subtype" BRIDGE_TIMEOUT = 35 UNASSIGNED_AREA = "Unassigned" + +CONFIG_URL = "https://device-login.lutron.com"