Skip to content

Commit

Permalink
Update deprecated attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
h4de5 committed Sep 4, 2021
1 parent 07d029d commit 6da5ac7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion custom_components/vimar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def state(self):
return self.get_state(self._measurement_name)

@property
def device_state_attributes(self):
def extra_state_attributes(self):
"""Return the state attributes."""
return self._device["status"][self._measurement_name]

Expand Down
52 changes: 26 additions & 26 deletions custom_components/vimar/vimar_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def __init__(self, device_id: int, vimarconnection: VimarLink, vimarproject: Vim

# self.entity_id = self._platform + "." + self.name.lower().replace(" ", "_") + "_" + self._device_id

@ property
@property
def should_poll(self):
"""No need to poll. Coordinator notifies entity of updates."""
return False

@ property
@property
def available(self):
"""Return if entity is available."""
return self._coordinator.last_update_success
Expand All @@ -69,10 +69,10 @@ async def async_will_remove_from_hass(self):
@property
def name(self):
"""Return the name of the device."""
return self._device['object_name']
return self._device["object_name"]

@property
def device_state_attributes(self):
def extra_state_attributes(self):
"""Return device specific state attributes."""
# see: https://developers.home-assistant.io/docs/dev_101_states/
return self._attributes
Expand All @@ -89,26 +89,26 @@ def request_statemachine_update(self):
def change_state(self, *args, **kwargs):
"""Change state on bus system and the local device state."""
state_changed = False
if 'status' in self._device and self._device['status']:
if "status" in self._device and self._device["status"]:

if args and len(args) > 0:
iter_args = iter(args)
for state, value in zip(iter_args, iter_args):
if state in self._device['status']:
if state in self._device["status"]:
state_changed = True
optionals = self._vimarconnection.get_optionals_param(state)
self.hass.async_add_executor_job(self._vimarconnection.set_device_status, self._device['status'][state]['status_id'], str(value), optionals)
self._device['status'][state]['status_value'] = str(value)
self.hass.async_add_executor_job(self._vimarconnection.set_device_status, self._device["status"][state]["status_id"], str(value), optionals)
self._device["status"][state]["status_value"] = str(value)
else:
_LOGGER.warning("Could not find state %s in device %s - %s - could not change value to: %s", state, self.name, self._device_id, value)

if kwargs and len(kwargs) > 0:
for state, value in kwargs.items():
if state in self._device['status']:
if state in self._device["status"]:
state_changed = True
optionals = self._vimarconnection.get_optionals_param(state)
self.hass.async_add_executor_job(self._vimarconnection.set_device_status, self._device['status'][state]['status_id'], str(value), optionals)
self._device['status'][state]['status_value'] = str(value)
self.hass.async_add_executor_job(self._vimarconnection.set_device_status, self._device["status"][state]["status_id"], str(value), optionals)
self._device["status"][state]["status_value"] = str(value)
else:
_LOGGER.warning("Could not find state %s in device %s - %s - could not change value to: %s", state, self.name, self._device_id, value)

Expand All @@ -120,38 +120,38 @@ def change_state(self, *args, **kwargs):
def get_state(self, state):
"""Get state of the local device state."""
if self.has_state(state):
return self._device['status'][state]['status_value']
return self._device["status"][state]["status_value"]
else:
_LOGGER.warning("Could not find state %s in device %s - %s - could not get value", state, self.name, self._device_id)
return None

def has_state(self, state):
"""Return true if local device has a given state."""
if 'status' in self._device and self._device['status'] and state in self._device['status']:
if "status" in self._device and self._device["status"] and state in self._device["status"]:
return True
else:
return False

@property
def icon(self):
"""Icon to use in the frontend, if any."""
if isinstance(self._device['icon'], str):
return self._device['icon']
elif isinstance(self._device['icon'], list):
return (self._device['icon'][1], self._device['icon'][0])[self.is_default_state]
if isinstance(self._device["icon"], str):
return self._device["icon"]
elif isinstance(self._device["icon"], list):
return (self._device["icon"][1], self._device["icon"][0])[self.is_default_state]

return self.ICON

@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return self._device['device_class']
return self._device["device_class"]

@property
def unique_id(self):
"""Return the ID of this device."""
# _LOGGER.debug("Unique Id: " + DOMAIN + '_' + self._platform + '_' + self._device_id + " - " + self.name)
return DOMAIN + '_' + self._platform + '_' + self._device_id
return DOMAIN + "_" + self._platform + "_" + self._device_id

def _reset_status(self):
"""Set status from _device to class variables."""
Expand All @@ -168,14 +168,14 @@ def vimar_setup_platform(vimar_entity_class: VimarEntity, hass: HomeAssistantTyp
if discovery_info is None:
return

_LOGGER.debug("Vimar %s started!", discovery_info['hass_data_key'])
_LOGGER.debug("Vimar %s started!", discovery_info["hass_data_key"])
entities = []

vimarconnection = hass.data[DOMAIN]['connection']
coordinator = hass.data[DOMAIN]['coordinator']
vimarproject = hass.data[DOMAIN]['project']
vimarconnection = hass.data[DOMAIN]["connection"]
coordinator = hass.data[DOMAIN]["coordinator"]
vimarproject = hass.data[DOMAIN]["project"]

devices = vimarproject.get_by_device_type(discovery_info['hass_data_key'])
devices = vimarproject.get_by_device_type(discovery_info["hass_data_key"])

if len(devices) != 0:
for device_id, device in devices.items():
Expand All @@ -185,9 +185,9 @@ def vimar_setup_platform(vimar_entity_class: VimarEntity, hass: HomeAssistantTyp
entities.append(vimar_entity_class(device_id, vimarconnection, vimarproject, coordinator))

if len(entities) != 0:
_LOGGER.info("Adding %d %s", len(entities), discovery_info['hass_data_key'])
_LOGGER.info("Adding %d %s", len(entities), discovery_info["hass_data_key"])
async_add_entities(entities)
# else:
# _LOGGER.warning("Vimar %s has no entities!", discovery_info['hass_data_key'])

_LOGGER.debug("Vimar %s complete!", discovery_info['hass_data_key'])
_LOGGER.debug("Vimar %s complete!", discovery_info["hass_data_key"])

0 comments on commit 6da5ac7

Please sign in to comment.