Skip to content

Commit

Permalink
Add support for Sengled Light Swtich
Browse files Browse the repository at this point in the history
Add support for Sengled Light Swtich
  • Loading branch information
jfarmer08 committed Jul 7, 2020
1 parent 407c756 commit 6b67d6b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
3 changes: 0 additions & 3 deletions custom_components/sengledapi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ def device_state_attributes(self):
"state": self._state,
"available": self._avaliable,
"device model": self._device_model,
# "ssid": self._ssid,
# "ip": self._ip,
# "rssi": self._rssi,
"mac": self._device_mac,
}

Expand Down
86 changes: 86 additions & 0 deletions custom_components/sengledapi/switch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/python3

"""Platform for switch integration."""
import logging
from .sengledapi.sengledapi import SengledApi
from . import DOMAIN

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.const import ATTR_ATTRIBUTION

# Import the device class from the component that you want to support
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice

_LOGGER = logging.getLogger(__name__)
ATTRIBUTION = "Data provided by Sengled"


async def async_setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Sengled Switch platform."""
_LOGGER.debug("""Creating new SengledApi switch component""")

# Add devices
add_entities(
SengledSwitch(switch)
for switch in await hass.data[DOMAIN]["sengledapi_account"].async_list_switch()
)


class SengledSwitch(SwitchDevice):
"""Representation of a Wyze Switch."""

def __init__(self, switch):
"""Initialize a Wyze Switch."""
self._switch = switch
self._name = switch._friendly_name
self._state = switch._state
self._avaliable = True
self._device_mac = switch._device_mac
self._device_model = switch._device_model

@property
def name(self):
"""Return the display name of this switch."""
return self._name

@property
def available(self):
"""Return the connection status of this switch"""
return self._avaliable

@property
def is_on(self):
"""Return true if switch is on."""
return self._state

@property
def unique_id(self):
return self._device_mac

@property
def device_state_attributes(self):
"""Return device attributes of the entity."""
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
"state": self._state,
"available": self._avaliable,
"device model": self._device_model,
"mac": self._device_mac,
}

async def async_turn_on(self, **kwargs):
"""Instruct the switch to turn on."""
await self._switch.async_turn_on()

async def async_turn_off(self, **kwargs):
"""Instruct the switch to turn off."""
await self._switch.async_turn_off()

async def async_update(self):
"""Fetch new state data for this switch.
This is the only method that should fetch new data for Home Assistant.
"""
await self._switch.async_update()
self._state = self._switch._state

0 comments on commit 6b67d6b

Please sign in to comment.