This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+22 -25
View File
@@ -9,30 +9,29 @@ from .common import VeSyncDevice
_LOGGER = logging.getLogger(__name__)
DEV_TYPE_TO_HA = {
'wifi-switch-1.3': 'outlet',
'ESW03-USA': 'outlet',
'ESW01-EU': 'outlet',
'ESW15-USA': 'outlet',
'ESWL01': 'switch',
'ESWL03': 'switch',
'ESO15-TB': 'outlet'
"wifi-switch-1.3": "outlet",
"ESW03-USA": "outlet",
"ESW01-EU": "outlet",
"ESW15-USA": "outlet",
"ESWL01": "switch",
"ESWL03": "switch",
"ESO15-TB": "outlet",
}
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up switches."""
async def async_discover(devices):
"""Add new devices to platform."""
_async_setup_entities(devices, async_add_entities)
disp = async_dispatcher_connect(
hass, VS_DISCOVERY.format(VS_SWITCHES), async_discover)
hass, VS_DISCOVERY.format(VS_SWITCHES), async_discover
)
hass.data[DOMAIN][VS_DISPATCHERS].append(disp)
_async_setup_entities(
hass.data[DOMAIN][VS_SWITCHES],
async_add_entities
)
_async_setup_entities(hass.data[DOMAIN][VS_SWITCHES], async_add_entities)
return True
@@ -41,19 +40,17 @@ def _async_setup_entities(devices, async_add_entities):
"""Check if device is online and add entity."""
dev_list = []
for dev in devices:
if DEV_TYPE_TO_HA.get(dev.device_type) == 'outlet':
if DEV_TYPE_TO_HA.get(dev.device_type) == "outlet":
dev_list.append(VeSyncSwitchHA(dev))
elif DEV_TYPE_TO_HA.get(dev.device_type) == 'switch':
elif DEV_TYPE_TO_HA.get(dev.device_type) == "switch":
dev_list.append(VeSyncLightSwitch(dev))
else:
_LOGGER.warning("%s - Unkown device type - %s",
dev.device_name, dev.device_type)
_LOGGER.warning(
"%s - Unkown device type - %s", dev.device_name, dev.device_type
)
continue
async_add_entities(
dev_list,
update_before_add=True
)
async_add_entities(dev_list, update_before_add=True)
class VeSyncSwitchHA(VeSyncDevice, SwitchDevice):
@@ -68,11 +65,11 @@ class VeSyncSwitchHA(VeSyncDevice, SwitchDevice):
def device_state_attributes(self):
"""Return the state attributes of the device."""
attr = {}
if hasattr(self.smartplug, 'weekly_energy_total'):
attr['voltage'] = self.smartplug.voltage
attr['weekly_energy_total'] = self.smartplug.weekly_energy_total
attr['monthly_energy_total'] = self.smartplug.monthly_energy_total
attr['yearly_energy_total'] = self.smartplug.yearly_energy_total
if hasattr(self.smartplug, "weekly_energy_total"):
attr["voltage"] = self.smartplug.voltage
attr["weekly_energy_total"] = self.smartplug.weekly_energy_total
attr["monthly_energy_total"] = self.smartplug.monthly_energy_total
attr["yearly_energy_total"] = self.smartplug.yearly_energy_total
return attr
@property