Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion homeassistant/components/lutron_caseta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
CONF_CA_CERTS,
CONF_CERTFILE,
CONF_KEYFILE,
CONFIG_URL,
DOMAIN,
LUTRON_CASETA_BUTTON_EVENT,
MANUFACTURER,
Expand Down Expand Up @@ -306,13 +307,15 @@ def __init__(self, device, bridge, bridge_device):
self._device = device
self._smartbridge = bridge
self._bridge_device = bridge_device
if "serial" not in self._device:
return
info = DeviceInfo(
identifiers={(DOMAIN, self.serial)},
manufacturer=MANUFACTURER,
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:
Expand Down
34 changes: 22 additions & 12 deletions homeassistant/components/lutron_caseta/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_SUGGESTED_AREA
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType
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(
Expand Down Expand Up @@ -39,6 +42,23 @@ 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="Lutron Occupancy",
name=self.name,
via_device=(CASETA_DOMAIN, self._bridge_device["serial"]),
configuration_url=CONFIG_URL,
entry_type=DeviceEntryType.SERVICE,
)
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."""
Expand All @@ -65,16 +85,6 @@ def unique_id(self):
"""Return a unique identifier."""
return f"occupancygroup_{self.device_id}"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not actually unique if you have multiple bridges. We need to prefix it with the bridge id as well since it is unique to the bridge.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can migrate them in 2022.6 though as its better to fix this now instead of adding risk


@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."""
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/lutron_caseta/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@
BRIDGE_TIMEOUT = 35

UNASSIGNED_AREA = "Unassigned"

CONFIG_URL = "https://device-login.lutron.com"