diff --git a/CODEOWNERS b/CODEOWNERS index 556ce10b18ed19475089c86cb16bcf3894f31ca4..5cc19809a47f4f6f2da97cf4ead5d09e5e549037 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -211,6 +211,7 @@ homeassistant/components/luci/* @fbradyirl @mzdrale homeassistant/components/luftdaten/* @fabaff homeassistant/components/lupusec/* @majuss homeassistant/components/lutron/* @JonGilmore +homeassistant/components/lutron_caseta/* @swails homeassistant/components/mastodon/* @fabaff homeassistant/components/matrix/* @tinloaf homeassistant/components/mcp23017/* @jardiamj diff --git a/homeassistant/components/lutron_caseta/__init__.py b/homeassistant/components/lutron_caseta/__init__.py index a3e384fd77bca93c1519cc72fe5b0965c654d265..47df6a221dde92254a9f04286f6f5c70ac86e841 100644 --- a/homeassistant/components/lutron_caseta/__init__.py +++ b/homeassistant/components/lutron_caseta/__init__.py @@ -33,7 +33,7 @@ CONFIG_SCHEMA = vol.Schema( extra=vol.ALLOW_EXTRA, ) -LUTRON_CASETA_COMPONENTS = ["light", "switch", "cover", "scene", "fan"] +LUTRON_CASETA_COMPONENTS = ["light", "switch", "cover", "scene", "fan", "binary_sensor"] async def async_setup(hass, base_config): diff --git a/homeassistant/components/lutron_caseta/binary_sensor.py b/homeassistant/components/lutron_caseta/binary_sensor.py new file mode 100644 index 0000000000000000000000000000000000000000..871f3c28664fc1309ea4a60a0f04b75e50e4e1fc --- /dev/null +++ b/homeassistant/components/lutron_caseta/binary_sensor.py @@ -0,0 +1,56 @@ +"""Support for Lutron Caseta Occupancy/Vacancy Sensors.""" +from pylutron_caseta import OCCUPANCY_GROUP_OCCUPIED + +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_OCCUPANCY, + BinarySensorDevice, +) + +from . import LUTRON_CASETA_SMARTBRIDGE, LutronCasetaDevice + + +async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): + """Set up the Lutron Caseta lights.""" + entities = [] + bridge = hass.data[LUTRON_CASETA_SMARTBRIDGE] + occupancy_groups = bridge.occupancy_groups + for occupancy_group in occupancy_groups.values(): + entity = LutronOccupancySensor(occupancy_group, bridge) + entities.append(entity) + + async_add_entities(entities, True) + + +class LutronOccupancySensor(LutronCasetaDevice, BinarySensorDevice): + """Representation of a Lutron occupancy group.""" + + @property + def device_class(self): + """Flag supported features.""" + return DEVICE_CLASS_OCCUPANCY + + @property + def is_on(self): + """Return the brightness of the light.""" + return self._device["status"] == OCCUPANCY_GROUP_OCCUPIED + + async def async_added_to_hass(self): + """Register callbacks.""" + self._smartbridge.add_occupancy_subscriber( + self.device_id, self.async_write_ha_state + ) + + @property + def device_id(self): + """Return the device ID used for calling pylutron_caseta.""" + return self._device["occupancy_group_id"] + + @property + def unique_id(self): + """Return a unique identifier.""" + return f"occupancygroup_{self.device_id}" + + @property + def device_state_attributes(self): + """Return the state attributes.""" + return {"device_id": self.device_id} diff --git a/homeassistant/components/lutron_caseta/manifest.json b/homeassistant/components/lutron_caseta/manifest.json index 3dd8c8fac2e15842054d73f85889d67954d1ad92..856bf285a1633065fdb39921ea367baf8f226aa7 100644 --- a/homeassistant/components/lutron_caseta/manifest.json +++ b/homeassistant/components/lutron_caseta/manifest.json @@ -2,7 +2,7 @@ "domain": "lutron_caseta", "name": "Lutron Caseta", "documentation": "https://www.home-assistant.io/integrations/lutron_caseta", - "requirements": ["pylutron-caseta==0.5.1"], + "requirements": ["pylutron-caseta==0.6.0"], "dependencies": [], - "codeowners": [] + "codeowners": ["@swails"] } diff --git a/requirements_all.txt b/requirements_all.txt index 927c8d35c13bb3b164d8f2647c45bdea6cef0b57..e2f81dbcf202b44801c3dcb5ac60b430a83a69da 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1364,7 +1364,7 @@ pylitejet==0.1 pyloopenergy==0.1.3 # homeassistant.components.lutron_caseta -pylutron-caseta==0.5.1 +pylutron-caseta==0.6.0 # homeassistant.components.lutron pylutron==0.2.5