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
This commit is contained in:
Matthew Donoughe 2019-11-26 12:06:14 -05:00 committed by Paulus Schoutsen
parent 9e971495f7
commit f8a36499c1
8 changed files with 49 additions and 28 deletions

View File

@ -0,0 +1,5 @@
{
"config": {
"title": "Lutron Caséta"
}
}

View File

@ -76,28 +76,39 @@ class LutronCasetaDevice(Entity):
[:param]device the device metadata [:param]device the device metadata
[:param]bridge the smartbridge object [:param]bridge the smartbridge object
""" """
self._device_id = device["device_id"] self._device = device
self._device_type = device["type"]
self._device_name = device["name"]
self._device_zone = device["zone"]
self._state = None
self._smartbridge = bridge self._smartbridge = bridge
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Register callbacks.""" """Register callbacks."""
self._smartbridge.add_subscriber( 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 @property
def name(self): def name(self):
"""Return the name of the device.""" """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 @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """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 return attr
@property @property

View File

@ -38,28 +38,28 @@ class LutronCasetaCover(LutronCasetaDevice, CoverDevice):
@property @property
def is_closed(self): def is_closed(self):
"""Return if the cover is closed.""" """Return if the cover is closed."""
return self._state["current_state"] < 1 return self._device["current_state"] < 1
@property @property
def current_cover_position(self): def current_cover_position(self):
"""Return the current position of cover.""" """Return the current position of cover."""
return self._state["current_state"] return self._device["current_state"]
async def async_close_cover(self, **kwargs): async def async_close_cover(self, **kwargs):
"""Close the cover.""" """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): async def async_open_cover(self, **kwargs):
"""Open the cover.""" """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): async def async_set_cover_position(self, **kwargs):
"""Move the shade to a specific position.""" """Move the shade to a specific position."""
if ATTR_POSITION in kwargs: if ATTR_POSITION in kwargs:
position = kwargs[ATTR_POSITION] 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): async def async_update(self):
"""Call when forcing a refresh of the device.""" """Call when forcing a refresh of the device."""
self._state = self._smartbridge.get_device_by_id(self._device_id) self._device = self._smartbridge.get_device_by_id(self.device_id)
_LOGGER.debug(self._state) _LOGGER.debug(self._device)

View File

@ -37,23 +37,23 @@ class LutronCasetaLight(LutronCasetaDevice, Light):
@property @property
def brightness(self): def brightness(self):
"""Return the brightness of the light.""" """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): async def async_turn_on(self, **kwargs):
"""Turn the light on.""" """Turn the light on."""
brightness = kwargs.get(ATTR_BRIGHTNESS, 255) 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): async def async_turn_off(self, **kwargs):
"""Turn the light off.""" """Turn the light off."""
self._smartbridge.set_value(self._device_id, 0) self._smartbridge.set_value(self.device_id, 0)
@property @property
def is_on(self): def is_on(self):
"""Return true if device is on.""" """Return true if device is on."""
return self._state["current_state"] > 0 return self._device["current_state"] > 0
async def async_update(self): async def async_update(self):
"""Call when forcing a refresh of the device.""" """Call when forcing a refresh of the device."""
self._state = self._smartbridge.get_device_by_id(self._device_id) self._device = self._smartbridge.get_device_by_id(self.device_id)
_LOGGER.debug(self._state) _LOGGER.debug(self._device)

View File

@ -3,7 +3,7 @@
"name": "Lutron caseta", "name": "Lutron caseta",
"documentation": "https://www.home-assistant.io/integrations/lutron_caseta", "documentation": "https://www.home-assistant.io/integrations/lutron_caseta",
"requirements": [ "requirements": [
"pylutron-caseta==0.5.0" "pylutron-caseta==0.5.1"
], ],
"dependencies": [], "dependencies": [],
"codeowners": [] "codeowners": []

View File

@ -0,0 +1,5 @@
{
"config": {
"title": "Lutron Caséta"
}
}

View File

@ -27,18 +27,18 @@ class LutronCasetaLight(LutronCasetaDevice, SwitchDevice):
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs):
"""Turn the switch on.""" """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): async def async_turn_off(self, **kwargs):
"""Turn the switch off.""" """Turn the switch off."""
self._smartbridge.turn_off(self._device_id) self._smartbridge.turn_off(self.device_id)
@property @property
def is_on(self): def is_on(self):
"""Return true if device is on.""" """Return true if device is on."""
return self._state["current_state"] > 0 return self._device["current_state"] > 0
async def async_update(self): async def async_update(self):
"""Update when forcing a refresh of the device.""" """Update when forcing a refresh of the device."""
self._state = self._smartbridge.get_device_by_id(self._device_id) self._device = self._smartbridge.get_device_by_id(self.device_id)
_LOGGER.debug(self._state) _LOGGER.debug(self._device)

View File

@ -1323,7 +1323,7 @@ pylitejet==0.1
pyloopenergy==0.1.3 pyloopenergy==0.1.3
# homeassistant.components.lutron_caseta # homeassistant.components.lutron_caseta
pylutron-caseta==0.5.0 pylutron-caseta==0.5.1
# homeassistant.components.lutron # homeassistant.components.lutron
pylutron==0.2.5 pylutron==0.2.5