Skip to content

Commit

Permalink
Replace deprecated device classes with SensorDeviceClass.
Browse files Browse the repository at this point in the history
Replace some deprecated functions
  • Loading branch information
gicamm committed May 5, 2024
1 parent 27e9adb commit 40af6ab
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
5 changes: 2 additions & 3 deletions custom_components/comelit/alarm_control_panel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Platform for sensor integration."""
import logging
from homeassistant.components.alarm_control_panel import (
AlarmControlPanelEntity, SUPPORT_ALARM_ARM_HOME, SUPPORT_ALARM_ARM_AWAY, SUPPORT_ALARM_ARM_NIGHT
AlarmControlPanelEntity, AlarmControlPanelEntityFeature
)

from .const import DOMAIN
Expand Down Expand Up @@ -45,5 +45,4 @@ def code_arm_required(self):

@property
def supported_features(self):
return SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT
# return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT
return AlarmControlPanelEntityFeature.ARM_AWAY | AlarmControlPanelEntityFeature.ARM_NIGHT
5 changes: 2 additions & 3 deletions custom_components/comelit/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Platform for sensor integration."""
import logging
from homeassistant.components.binary_sensor import BinarySensorEntity, DEVICE_CLASS_PRESENCE, DEVICE_CLASS_MOTION
from homeassistant.components.binary_sensor import BinarySensorEntity, BinarySensorDeviceClass
from homeassistant.const import STATE_ON

from .comelit_device import ComelitDevice
Expand Down Expand Up @@ -29,5 +29,4 @@ def is_on(self):

@property
def device_class(self):
return DEVICE_CLASS_MOTION

return BinarySensorDeviceClass.MOTION
13 changes: 8 additions & 5 deletions custom_components/comelit/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

from homeassistant.components.climate import HVACMode, HVACAction

from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE
from homeassistant.components.climate import (
ClimateEntityFeature
)

from homeassistant.const import (
ATTR_TEMPERATURE,
TEMP_CELSIUS,
STATE_OFF,
STATE_IDLE,
STATE_ON
)
from homeassistant.components.sensor import (
UnitOfTemperature,
)

from .const import DOMAIN

Expand Down Expand Up @@ -55,7 +58,7 @@ def target_temperature(self):

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

@property
def current_temperature(self):
Expand All @@ -67,7 +70,7 @@ def current_humidity(self):

@property
def supported_features(self):
return SUPPORT_TARGET_TEMPERATURE
return ClimateEntityFeature.TARGET_TEMPERATURE

def set_temperature(self, **kwargs):
temperature = kwargs.get(ATTR_TEMPERATURE)
Expand Down
3 changes: 1 addition & 2 deletions custom_components/comelit/cover.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Platform for light integration."""
import time
import logging

from homeassistant.const import STATE_OPEN, STATE_CLOSED, STATE_OPENING, STATE_CLOSING
from homeassistant.const import STATE_CLOSED, STATE_OPENING, STATE_CLOSING

from .const import DOMAIN
from homeassistant.components.cover import (CoverEntity)
Expand Down
6 changes: 3 additions & 3 deletions custom_components/comelit/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Import the device class from the component that you want to support
from homeassistant.components.light import (
ATTR_BRIGHTNESS, PLATFORM_SCHEMA, LightEntity, COLOR_MODE_BRIGHTNESS)
ATTR_BRIGHTNESS, LightEntity, ColorMode)
from homeassistant.const import STATE_ON, STATE_OFF

from .const import DOMAIN
Expand Down Expand Up @@ -32,11 +32,11 @@ def is_on(self):

@property
def supported_color_modes(self):
return None if self._brightness is None else {COLOR_MODE_BRIGHTNESS}
return ColorMode.BRIGHTNESS if self._brightness else {ColorMode.ONOFF}

@property
def color_mode(self):
return None if self._brightness is None else COLOR_MODE_BRIGHTNESS
return ColorMode.BRIGHTNESS if self._brightness else ColorMode.ONOFF

@property
def brightness(self):
Expand Down
17 changes: 11 additions & 6 deletions custom_components/comelit/sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""Platform for sensor integration."""
import logging
from homeassistant.const import (
TEMP_CELSIUS, POWER_WATT, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_POWER)
UnitOfPower,
UnitOfTemperature,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
)

from .const import DOMAIN
from .comelit_device import ComelitDevice
Expand Down Expand Up @@ -55,20 +60,20 @@ def __init__(self, id, description, value, prod):
else:
type = "power_cons"
icon = "mdi:power-plug"
ComelitSensor.__init__(self, id, description, value, type, icon, POWER_WATT, DEVICE_CLASS_POWER)
ComelitSensor.__init__(self, id, description, value, type, icon, UnitOfPower.WATT, SensorDeviceClass.POWER)


class TemperatureSensor(ComelitSensor):
"""Representation of a Sensor."""

def __init__(self, id, description, value):
"""Initialize the sensor."""
ComelitSensor.__init__(self, id, description, value, "temperature", "mdi:home-thermometer", TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE)
ComelitSensor.__init__(self, id, description, value, "temperature", "mdi:home-thermometer",
UnitOfTemperature.CELSIUS, SensorDeviceClass.TEMPERATURE)


class HumiditySensor(ComelitSensor):
def __init__(self, id, description, value):
"""Initialize the sensor."""
ComelitSensor.__init__(self, id, description, value, "humidity", "mdi:water-percent", "%", DEVICE_CLASS_HUMIDITY)


ComelitSensor.__init__(self, id, description, value, "humidity", "mdi:water-percent", "%",
SensorDeviceClass.HUMIDITY)
1 change: 0 additions & 1 deletion custom_components/comelit/vedo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import time
import requests
import logging
import signal
from threading import Thread
from wrapt_timeout_decorator import *
from homeassistant.const import STATE_ALARM_DISARMED, STATE_ALARM_ARMED_AWAY, STATE_ON, STATE_OFF
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# sudo apt install python3-pip python3-dev python3-venv autoconf libssl-dev libxml2-dev libxslt1-dev libjpeg-dev libffi-dev libudev-dev zlib1g-dev pkg-config libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libswscale-dev libavresample-dev libavfilter-dev ffmpeg
homeassistant==2022.5.2
homeassistant==2023.7.3
paho-mqtt
wrapt-timeout-decorator
dill
Expand Down

1 comment on commit 40af6ab

@Slen18
Copy link

@Slen18 Slen18 commented on 40af6ab May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ciao
non so se è il campo gusto,sono nuovo e all'inizo, ho un sistema domotico Comelit Serial Bridge e non so come chreare i sensori di potenza. se gentilmente mi puoi illumnare.grazie

Please sign in to comment.