Skip to content

Commit

Permalink
Fixed but where if there are no smartplugs then switches fail due to …
Browse files Browse the repository at this point in the history
…nonetype issue #71
  • Loading branch information
asantaga committed Feb 24, 2020
1 parent a417c89 commit a5e2cc0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 6 additions & 5 deletions custom_components/wiser/sensor.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
data = hass.data[DOMAIN] # Get Handler
wiser_devices = []

# Add device sensors
for device in data.wiserhub.getDevices():
wiser_devices.append(
WiserDeviceSensor(data, device.get("id"), device.get("ProductType"))
)
# Add device sensors, only if there are some
if data.wiserhub.getDevices() is not None:
for device in data.wiserhub.getDevices():
wiser_devices.append(
WiserDeviceSensor(data, device.get("id"), device.get("ProductType"))
)

# Add cloud status sensor
wiser_devices.append(WiserSystemCloudSensor(data, sensorType="Cloud Sensor"))
Expand Down
15 changes: 10 additions & 5 deletions custom_components/wiser/switch.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
"""Add the Wiser System Switch entities"""
data = hass.data[DOMAIN]

# Add System Switches
wiser_switches = [
WiserSwitch(hass, data, switchType, hubKey) for switchType, hubKey in WISER_SWITCHES.items()
]
wiser_smart_plugs = [
WiserSmartPlug(hass, data, plug.get("id"), plug.get("Name")) for plug in data.wiserhub.getSmartPlugs()
]

async_add_entities(wiser_switches)
async_add_entities(wiser_smart_plugs)

# Add SmartPlugs (if any)
if data.wiserhub.getSmartPlugs() is not None:
wiser_smart_plugs = [
WiserSmartPlug(hass, data, plug.get("id"), plug.get("Name")) for plug in data.wiserhub.getSmartPlugs()
]
async_add_entities(wiser_smart_plugs)



@callback
def set_smartplug_mode(service):
Expand Down

0 comments on commit a5e2cc0

Please sign in to comment.