Skip to content

Commit

Permalink
Migration to EntityFeature enums
Browse files Browse the repository at this point in the history
  • Loading branch information
sandmanpr committed Mar 15, 2024
1 parent 423fe1d commit 1960522
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 60 deletions.
15 changes: 9 additions & 6 deletions custom_components/skykettle/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""Support for SkyKettle."""
import logging
from .const import *
from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import *
from datetime import timedelta

import homeassistant.helpers.event as ev
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (ATTR_SW_VERSION, CONF_DEVICE,
CONF_FRIENDLY_NAME, CONF_MAC, CONF_PASSWORD,
CONF_SCAN_INTERVAL, Platform)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.entity import DeviceInfo
from datetime import timedelta

from .const import *
from .kettle_connection import KettleConnection
from .skykettle import SkyKettle

_LOGGER = logging.getLogger(__name__)

Expand Down
15 changes: 8 additions & 7 deletions custom_components/skykettle/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"""Config flow for Sky Kettle integration."""

import logging
import re
import secrets
import traceback
import sys
import asyncio
import subprocess

import voluptuous as vol
from homeassistant.components import bluetooth
from homeassistant.const import *

import homeassistant.helpers.config_validation as cv
from homeassistant import config_entries
from homeassistant.components import bluetooth
from homeassistant.const import (CONF_DEVICE, CONF_FRIENDLY_NAME, CONF_MAC,
CONF_PASSWORD, CONF_SCAN_INTERVAL)
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv

from .const import *
from .kettle_connection import KettleConnection
from .skykettle import SkyKettle
Expand Down
9 changes: 6 additions & 3 deletions custom_components/skykettle/kettle_connection.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import logging
import asyncio
import logging
import traceback
from time import monotonic

from bleak import BleakClient

from homeassistant.components import bluetooth
from bleak import BleakScanner, BleakClient

from .const import *
from .skykettle import SkyKettle
import traceback

_LOGGER = logging.getLogger(__name__)

Expand Down
21 changes: 9 additions & 12 deletions custom_components/skykettle/light.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
"""SkyKettle."""
import logging

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_RGB_COLOR,
COLOR_MODE_RGB,
LightEntity,
)
from homeassistant.components.light import (ATTR_BRIGHTNESS, ATTR_RGB_COLOR,
ColorMode, LightEntity, LightEntityFeature)
from homeassistant.const import CONF_FRIENDLY_NAME, STATE_OFF
from homeassistant.helpers.dispatcher import (async_dispatcher_connect,
async_dispatcher_send)
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.dispatcher import async_dispatcher_send, async_dispatcher_connect
from homeassistant.const import *

from .skykettle import SkyKettle
from .const import *
from .skykettle import SkyKettle

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -155,17 +152,17 @@ def is_on(self):
@property
def supported_features(self):
"""Flag supported features."""
return 0
return LightEntityFeature(0)

@property
def color_mode(self):
"""Return the color mode of the light."""
return COLOR_MODE_RGB
return ColorMode.RGB

@property
def supported_color_modes(self):
"""Flag supported color modes."""
return {COLOR_MODE_RGB}
return {ColorMode.RGB}

async def async_turn_on(self, **kwargs):
"""Turn the light on."""
Expand Down
18 changes: 10 additions & 8 deletions custom_components/skykettle/number.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""SkyKettle."""
import logging

from homeassistant.components.number import NumberMode, NumberEntity
from homeassistant.components.number import NumberEntity, NumberMode
from homeassistant.const import (CONF_FRIENDLY_NAME, UnitOfTemperature,
UnitOfTime)
from homeassistant.helpers.dispatcher import (async_dispatcher_connect,
async_dispatcher_send)
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.dispatcher import async_dispatcher_send, async_dispatcher_connect
from homeassistant.const import *

from .skykettle import SkyKettle
from .const import *
from .skykettle import SkyKettle

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -142,15 +144,15 @@ def native_unit_of_measurement(self):
if self.number_type == NUMBER_TYPE_BOIL_TIME:
return None
if self.number_type == NUMBER_TEMPERATURE_LOW:
return "°C"
return UnitOfTemperature.CELSIUS
if self.number_type == NUMBER_TEMPERATURE_MID:
return "°C"
return UnitOfTemperature.CELSIUS
if self.number_type == NUMBER_TEMPERATURE_HIGH:
return "°C"
return UnitOfTemperature.CELSIUS
if self.number_type == NUMBER_COLOR_INTERVAL:
return "secs"
if self.number_type == NUMBER_LAMP_AUTO_OFF_HOURS:
return "h"
return UnitOfTime.HOURS

@property
def native_value(self):
Expand Down
16 changes: 9 additions & 7 deletions custom_components/skykettle/sensor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""SkyKettle."""
import logging

from homeassistant.components.sensor import SensorEntity, SensorStateClass, SensorDeviceClass
from homeassistant.helpers.entity import EntityCategory
from homeassistant.components.sensor import (SensorDeviceClass, SensorEntity,
SensorStateClass)
from homeassistant.const import (CONF_FRIENDLY_NAME, PERCENTAGE, UnitOfEnergy,
UnitOfTime)
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.const import *
from homeassistant.helpers.entity import EntityCategory

from .skykettle import SkyKettle
from .const import *
from .skykettle import SkyKettle

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -154,11 +156,11 @@ def state_class(self):
@property
def native_unit_of_measurement(self):
if self.sensor_type == SENSOR_TYPE_ENERGY:
return ENERGY_WATT_HOUR
return UnitOfEnergy.WATT_HOUR
if self.sensor_type == SENSOR_TYPE_ONTIME:
return TIME_SECONDS
return UnitOfTime.SECONDS
if self.sensor_type == SENSOR_TYPE_WATER_FRESHNESS:
return TIME_HOURS
return UnitOfTime.HOURS
if self.sensor_type == SENSOR_TYPE_SUCCESS_RATE:
return PERCENTAGE
return None
Expand Down
8 changes: 4 additions & 4 deletions custom_components/skykettle/skykettle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import calendar
import logging
from struct import pack, unpack
from collections import namedtuple
import time
from datetime import datetime, timedelta
import calendar
from abc import abstractmethod
from collections import namedtuple
from datetime import datetime, timedelta
from struct import pack, unpack

_LOGGER = logging.getLogger(__name__)

Expand Down
7 changes: 4 additions & 3 deletions custom_components/skykettle/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import logging

from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
from homeassistant.const import CONF_FRIENDLY_NAME
from homeassistant.helpers.dispatcher import (async_dispatcher_connect,
async_dispatcher_send)
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.dispatcher import async_dispatcher_send, async_dispatcher_connect
from homeassistant.const import *

from .skykettle import SkyKettle
from .const import *
from .skykettle import SkyKettle

_LOGGER = logging.getLogger(__name__)

Expand Down
21 changes: 11 additions & 10 deletions custom_components/skykettle/water_heater.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""SkyKettle."""
import logging
from homeassistant.components.water_heater import (
SUPPORT_OPERATION_MODE,
SUPPORT_TARGET_TEMPERATURE,
WaterHeaterEntity,
)
from homeassistant.helpers.dispatcher import async_dispatcher_send, async_dispatcher_connect
from homeassistant.const import *

from .skykettle import SkyKettle
from homeassistant.components.water_heater import (WaterHeaterEntity,
WaterHeaterEntityFeature)
from homeassistant.const import (ATTR_SW_VERSION, ATTR_TEMPERATURE,
CONF_FRIENDLY_NAME, CONF_SCAN_INTERVAL,
STATE_OFF, UnitOfTemperature)
from homeassistant.helpers.dispatcher import (async_dispatcher_connect,
async_dispatcher_send)

from .const import *
from .skykettle import SkyKettle

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,11 +78,11 @@ def entity_category(self):

@property
def supported_features(self):
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE
return WaterHeaterEntityFeature.TARGET_TEMPERATURE | WaterHeaterEntityFeature.OPERATION_MODE

@property
def temperature_unit(self):
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

@property
def min_temp(self):
Expand Down

0 comments on commit 1960522

Please sign in to comment.