From f8a36499c1d308c98fb1ad67d778784de82b0d92 Mon Sep 17 00:00:00 2001 From: Matthew Donoughe Date: Tue, 26 Nov 2019 12:06:14 -0500 Subject: [PATCH] Add serial to caseta devices (#28886) * add model and serial to caseta devices * use just serial for unique id * add display name for entity registry * remove caseta device model * just store device * state and device are the same --- .../lutron_caseta/.translations/en.json | 5 ++++ .../components/lutron_caseta/__init__.py | 27 +++++++++++++------ .../components/lutron_caseta/cover.py | 14 +++++----- .../components/lutron_caseta/light.py | 12 ++++----- .../components/lutron_caseta/manifest.json | 2 +- .../components/lutron_caseta/strings.json | 5 ++++ .../components/lutron_caseta/switch.py | 10 +++---- requirements_all.txt | 2 +- 8 files changed, 49 insertions(+), 28 deletions(-) create mode 100644 homeassistant/components/lutron_caseta/.translations/en.json create mode 100644 homeassistant/components/lutron_caseta/strings.json diff --git a/homeassistant/components/lutron_caseta/.translations/en.json b/homeassistant/components/lutron_caseta/.translations/en.json new file mode 100644 index 00000000000..cb7ab8c767e --- /dev/null +++ b/homeassistant/components/lutron_caseta/.translations/en.json @@ -0,0 +1,5 @@ +{ + "config": { + "title": "Lutron Caséta" + } +} \ No newline at end of file diff --git a/homeassistant/components/lutron_caseta/__init__.py b/homeassistant/components/lutron_caseta/__init__.py index 4d4b2e90fd6..54bde9538af 100644 --- a/homeassistant/components/lutron_caseta/__init__.py +++ b/homeassistant/components/lutron_caseta/__init__.py @@ -76,28 +76,39 @@ class LutronCasetaDevice(Entity): [:param]device the device metadata [:param]bridge the smartbridge object """ - self._device_id = device["device_id"] - self._device_type = device["type"] - self._device_name = device["name"] - self._device_zone = device["zone"] - self._state = None + self._device = device self._smartbridge = bridge async def async_added_to_hass(self): """Register callbacks.""" self._smartbridge.add_subscriber( - self._device_id, self.async_schedule_update_ha_state + self.device_id, self.async_schedule_update_ha_state ) + @property + def device_id(self): + """Return the device ID used for calling pylutron_caseta.""" + return self._device["device_id"] + @property def name(self): """Return the name of the device.""" - return self._device_name + return self._device["name"] + + @property + def serial(self): + """Return the serial number of the device.""" + return self._device["serial"] + + @property + def unique_id(self): + """Return the unique ID of the device (serial).""" + return str(self.serial) @property def device_state_attributes(self): """Return the state attributes.""" - attr = {"Device ID": self._device_id, "Zone ID": self._device_zone} + attr = {"Device ID": self.device_id, "Zone ID": self._device["zone"]} return attr @property diff --git a/homeassistant/components/lutron_caseta/cover.py b/homeassistant/components/lutron_caseta/cover.py index 786e569da32..afd669153e0 100644 --- a/homeassistant/components/lutron_caseta/cover.py +++ b/homeassistant/components/lutron_caseta/cover.py @@ -38,28 +38,28 @@ class LutronCasetaCover(LutronCasetaDevice, CoverDevice): @property def is_closed(self): """Return if the cover is closed.""" - return self._state["current_state"] < 1 + return self._device["current_state"] < 1 @property def current_cover_position(self): """Return the current position of cover.""" - return self._state["current_state"] + return self._device["current_state"] async def async_close_cover(self, **kwargs): """Close the cover.""" - self._smartbridge.set_value(self._device_id, 0) + self._smartbridge.set_value(self.device_id, 0) async def async_open_cover(self, **kwargs): """Open the cover.""" - self._smartbridge.set_value(self._device_id, 100) + self._smartbridge.set_value(self.device_id, 100) async def async_set_cover_position(self, **kwargs): """Move the shade to a specific position.""" if ATTR_POSITION in kwargs: position = kwargs[ATTR_POSITION] - self._smartbridge.set_value(self._device_id, position) + self._smartbridge.set_value(self.device_id, position) async def async_update(self): """Call when forcing a refresh of the device.""" - self._state = self._smartbridge.get_device_by_id(self._device_id) - _LOGGER.debug(self._state) + self._device = self._smartbridge.get_device_by_id(self.device_id) + _LOGGER.debug(self._device) diff --git a/homeassistant/components/lutron_caseta/light.py b/homeassistant/components/lutron_caseta/light.py index a764ad4b73a..af225d2939d 100644 --- a/homeassistant/components/lutron_caseta/light.py +++ b/homeassistant/components/lutron_caseta/light.py @@ -37,23 +37,23 @@ class LutronCasetaLight(LutronCasetaDevice, Light): @property def brightness(self): """Return the brightness of the light.""" - return to_hass_level(self._state["current_state"]) + return to_hass_level(self._device["current_state"]) async def async_turn_on(self, **kwargs): """Turn the light on.""" brightness = kwargs.get(ATTR_BRIGHTNESS, 255) - self._smartbridge.set_value(self._device_id, to_lutron_level(brightness)) + self._smartbridge.set_value(self.device_id, to_lutron_level(brightness)) async def async_turn_off(self, **kwargs): """Turn the light off.""" - self._smartbridge.set_value(self._device_id, 0) + self._smartbridge.set_value(self.device_id, 0) @property def is_on(self): """Return true if device is on.""" - return self._state["current_state"] > 0 + return self._device["current_state"] > 0 async def async_update(self): """Call when forcing a refresh of the device.""" - self._state = self._smartbridge.get_device_by_id(self._device_id) - _LOGGER.debug(self._state) + self._device = self._smartbridge.get_device_by_id(self.device_id) + _LOGGER.debug(self._device) diff --git a/homeassistant/components/lutron_caseta/manifest.json b/homeassistant/components/lutron_caseta/manifest.json index d1501a562db..e9df5ad1d46 100644 --- a/homeassistant/components/lutron_caseta/manifest.json +++ b/homeassistant/components/lutron_caseta/manifest.json @@ -3,7 +3,7 @@ "name": "Lutron caseta", "documentation": "https://www.home-assistant.io/integrations/lutron_caseta", "requirements": [ - "pylutron-caseta==0.5.0" + "pylutron-caseta==0.5.1" ], "dependencies": [], "codeowners": [] diff --git a/homeassistant/components/lutron_caseta/strings.json b/homeassistant/components/lutron_caseta/strings.json new file mode 100644 index 00000000000..cb7ab8c767e --- /dev/null +++ b/homeassistant/components/lutron_caseta/strings.json @@ -0,0 +1,5 @@ +{ + "config": { + "title": "Lutron Caséta" + } +} \ No newline at end of file diff --git a/homeassistant/components/lutron_caseta/switch.py b/homeassistant/components/lutron_caseta/switch.py index fabd4e7fa76..f6eb846ecfb 100644 --- a/homeassistant/components/lutron_caseta/switch.py +++ b/homeassistant/components/lutron_caseta/switch.py @@ -27,18 +27,18 @@ class LutronCasetaLight(LutronCasetaDevice, SwitchDevice): async def async_turn_on(self, **kwargs): """Turn the switch on.""" - self._smartbridge.turn_on(self._device_id) + self._smartbridge.turn_on(self.device_id) async def async_turn_off(self, **kwargs): """Turn the switch off.""" - self._smartbridge.turn_off(self._device_id) + self._smartbridge.turn_off(self.device_id) @property def is_on(self): """Return true if device is on.""" - return self._state["current_state"] > 0 + return self._device["current_state"] > 0 async def async_update(self): """Update when forcing a refresh of the device.""" - self._state = self._smartbridge.get_device_by_id(self._device_id) - _LOGGER.debug(self._state) + self._device = self._smartbridge.get_device_by_id(self.device_id) + _LOGGER.debug(self._device) diff --git a/requirements_all.txt b/requirements_all.txt index aae71e2028a..808b26f86a4 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1323,7 +1323,7 @@ pylitejet==0.1 pyloopenergy==0.1.3 # homeassistant.components.lutron_caseta -pylutron-caseta==0.5.0 +pylutron-caseta==0.5.1 # homeassistant.components.lutron pylutron==0.2.5