https://github.com/peterbuga/HASS-sonoff-ewelink/blob/master/sonoff.py
Trying to create an attribute friendly_name to represent self._device_name
class SonoffDevice(Entity):
"""Representation of a Sonoff device"""
def __init__(self, hass, device):
"""Initialize the device."""
self._hass = hass
self._name = 'sonoff_{}'.format(device['deviceid'])
self._device_name = device['name']
self._deviceid = device['deviceid']
self._user_apikey = device['apikey']
self._state = device['params']['switch'] == 'on'
self._available = device['online']
self._attributes = {
'device_name' : self._device_name,
'device_id' : self._deviceid,
'friendly_name' : self._device_name
}
def get_device(self, deviceid):
for device in self._hass.data[DOMAIN].get_devices():
if 'deviceid' in device and device['deviceid'] == deviceid:
return device
return None
def get_state(self, deviceid):
device = self.get_device(deviceid)
return device['params']['switch'] == 'on' if device else False
def get_available(self, deviceid):
device = self.get_device(deviceid)
return device['online'] if device else False
@property
def should_poll(self):
"""Return the polling state."""
return True
@property
def name(self):
"""Return the name of the switch."""
return self._name
@property
def is_on(self):
"""Return true if device is on."""
return self.get_state(self._deviceid)
@property
def available(self):
"""Return true if device is online."""
return self.get_available(self._deviceid)
# @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Update device state."""
# we don't update here because there's 1 single thread that can be active at anytime
# i.e. eWeLink API allows only 1 active session
pass
def turn_on(self, **kwargs):
"""Turn the device on."""
self._state = self._hass.data[DOMAIN].switch(self._deviceid, True)
self.schedule_update_ha_state()
def turn_off(self, **kwargs):
"""Turn the device off."""
self._state = self._hass.data[DOMAIN].switch(self._deviceid, False)
self.schedule_update_ha_state()
@property
def device_state_attributes(self):
"""Return device specific state attributes."""
return self._attributes
Nothing seems to be working
Would really appreciate your help.