Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwitchDevice is depreciated update to SwitchEntity #10

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions custom_components/switch/konke.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
Support for the Konke outlet.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.konke/
https://home-assistant.io/components/light.opple/
"""

import logging
import time

import voluptuous as vol

from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
from homeassistant.components.switch import SwitchEntity, PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME, CONF_HOST
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['pykonkeio>=2.1.8']
REQUIREMENTS = ['pykonkeio>=2.1.7']

_LOGGER = logging.getLogger(__name__)

Expand All @@ -40,10 +40,8 @@


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up Konke switch platform."""
from pykonkeio.manager import get_device
from pykonkeio.error import DeviceNotSupport

name = config[CONF_NAME]
host = config[CONF_HOST]
model = config[CONF_MODEL].lower()
Expand All @@ -63,7 +61,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
for i in range(device.socket_count):
entities.append(KonkePowerStripOutlet(powerstrip, name, i))

for i in range(device.usb_count if hasattr(device, 'usb_count') else 0):
for i in range(device.usb_count or 0):
entities.append(KonkePowerStripUSB(powerstrip, name, i))
else:
entities.append(KonkeOutlet(name, device, model))
Expand All @@ -73,7 +71,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities(entities)


class KonkeOutlet(SwitchDevice):
class KonkeOutlet(SwitchEntity):

def __init__(self, name, device, model=None):
self._name = name
Expand All @@ -93,8 +91,8 @@ def available(self) -> bool:

@property
def unique_id(self):
"""Return unique ID for switch."""
return self._device.uuid
"""Return unique ID for light."""
return self._device.mac

@property
def name(self):
Expand Down Expand Up @@ -135,7 +133,7 @@ async def async_update(self):
_LOGGER.warning('Device is offline %s', self.entity_id)


class KonkeUsbSwitch(SwitchDevice):
class KonkeUsbSwitch(SwitchEntity):
def __init__(self, name, device):
self._name = name
self._device = device
Expand All @@ -152,8 +150,8 @@ def available(self) -> bool:

@property
def unique_id(self):
"""Return unique ID for switch."""
return '%s:usb' % self._device.uuid
"""Return unique ID for light."""
return '%s:usb' % self._device.mac

@property
def name(self):
Expand Down Expand Up @@ -186,6 +184,7 @@ async def async_update(self):
_LOGGER.warning('Device is offline %s', self.entity_id)



class KonkePowerStrip(object):

def __init__(self, device, name: str):
Expand All @@ -202,7 +201,7 @@ def available(self) -> bool:
@property
def unique_id(self):
"""Return unique ID for outlet."""
return self._device.uuid
return self._device.mac

@property
def name(self):
Expand Down Expand Up @@ -246,7 +245,7 @@ async def async_update(self):
_LOGGER.warning('Device is offline %s', self.unique_id)


class KonkePowerStripOutlet(SwitchDevice):
class KonkePowerStripOutlet(SwitchEntity):
"""Outlet in Konke Power Strip."""

def __init__(self, powerstrip: KonkePowerStrip, name: str, index: int):
Expand Down Expand Up @@ -296,7 +295,7 @@ async def async_update(self):
await self._powerstrip.async_update()


class KonkePowerStripUSB(SwitchDevice):
class KonkePowerStripUSB(SwitchEntity):
"""Outlet in Konke Power Strip."""

def __init__(self, powerstrip: KonkePowerStrip, name: str, index: int):
Expand Down