forked from platypush/platypush
[switch.tplink] Don't thrown an exception if a device doesn't support current_consumption.
This commit is contained in:
parent
f364be17e3
commit
f032957d0b
1 changed files with 13 additions and 3 deletions
|
@ -185,10 +185,20 @@ class SwitchTplinkPlugin(RunnablePlugin, SwitchEntityManager):
|
||||||
device = self._get_device(device)
|
device = self._get_device(device)
|
||||||
return self._set(device, not device.is_on)
|
return self._set(device, not device.is_on)
|
||||||
|
|
||||||
@staticmethod
|
def _current_consumption(self, device: SmartDevice) -> Optional[float]:
|
||||||
def _serialize(device: SmartDevice) -> dict:
|
try:
|
||||||
|
return device.current_consumption()
|
||||||
|
except SmartDeviceException as e:
|
||||||
|
self.logger.warning(
|
||||||
|
'Could not retrieve current consumption for device %s: %s',
|
||||||
|
device.host,
|
||||||
|
e,
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _serialize(self, device: SmartDevice) -> dict:
|
||||||
return {
|
return {
|
||||||
'current_consumption': device.current_consumption(),
|
'current_consumption': self._current_consumption(device),
|
||||||
'id': device.host,
|
'id': device.host,
|
||||||
'ip': device.host,
|
'ip': device.host,
|
||||||
'host': device.host,
|
'host': device.host,
|
||||||
|
|
Loading…
Reference in a new issue