[go: nahoru, domu]

Skip to content

Commit

Permalink
Update out-dated api usages
Browse files Browse the repository at this point in the history
  • Loading branch information
qqaatw committed Feb 12, 2023
1 parent 152feb1 commit 3ff38d6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 36 deletions.
7 changes: 3 additions & 4 deletions custom_components/jcihitachi_tw/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""JciHitachi integration."""
import logging

from homeassistant.components.binary_sensor import (DEVICE_CLASS_PROBLEM,
BinarySensorEntity)
from homeassistant.components.binary_sensor import (BinarySensorEntity, BinarySensorDeviceClass)

from . import API, COORDINATOR, DOMAIN, UPDATED_DATA, JciHitachiEntity

Expand Down Expand Up @@ -51,7 +50,7 @@ def is_on(self):

@property
def device_class(self):
return DEVICE_CLASS_PROBLEM
return BinarySensorDeviceClass.PROBLEM

@property
def unique_id(self):
Expand Down Expand Up @@ -80,7 +79,7 @@ def is_on(self):

@property
def device_class(self):
return DEVICE_CLASS_PROBLEM
return BinarySensorDeviceClass.PROBLEM

@property
def unique_id(self):
Expand Down
4 changes: 2 additions & 2 deletions custom_components/jcihitachi_tw/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
SWING_BOTH,
SWING_HORIZONTAL,
SWING_OFF, SWING_VERTICAL)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature

from . import API, COORDINATOR, DOMAIN, UPDATED_DATA, JciHitachiEntity

Expand Down Expand Up @@ -94,7 +94,7 @@ def supported_features(self):
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

@property
def current_temperature(self):
Expand Down
6 changes: 2 additions & 4 deletions custom_components/jcihitachi_tw/humidifier.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""JciHitachi integration."""
import logging

from homeassistant.components.humidifier import HumidifierEntity
from homeassistant.components.humidifier.const import (
DEVICE_CLASS_DEHUMIDIFIER, SUPPORT_MODES)
from homeassistant.components.humidifier import HumidifierEntity, HumidifierDeviceClass, SUPPORT_MODES

from . import API, COORDINATOR, DOMAIN, UPDATED_DATA, JciHitachiEntity

Expand Down Expand Up @@ -130,7 +128,7 @@ def is_on(self):

@property
def device_class(self):
return DEVICE_CLASS_DEHUMIDIFIER
return HumidifierDeviceClass.DEHUMIDIFIER

@property
def unique_id(self):
Expand Down
64 changes: 38 additions & 26 deletions custom_components/jcihitachi_tw/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

from homeassistant.components.sensor import (STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorDeviceClass,
SensorEntity)
from homeassistant.const import (CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
DEVICE_CLASS_DATE, DEVICE_CLASS_ENERGY,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PM25,
DEVICE_CLASS_TEMPERATURE,
ENERGY_KILO_WATT_HOUR, PERCENTAGE,
TEMP_CELSIUS)
from homeassistant.const import (CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, PERCENTAGE,
UnitOfEnergy, UnitOfTemperature)

from . import API, COORDINATOR, DOMAIN, UPDATED_DATA, JciHitachiEntity

Expand All @@ -19,6 +16,11 @@
ODOR_LEVEL_LOW = "Low"
ODOR_LEVEL_MIDDLE = "Middle"
ODOR_LEVEL_HIGH = "High"
ODOR_LEVELS = [
ODOR_LEVEL_LOW,
ODOR_LEVEL_MIDDLE,
ODOR_LEVEL_HIGH,
]


async def _async_setup(hass, async_add):
Expand Down Expand Up @@ -69,7 +71,7 @@ def name(self):
return f"{self._thing.name} Indoor Humidity"

@property
def state(self):
def native_value(self):
"""Return the indoor humidity."""
status = self.hass.data[DOMAIN][UPDATED_DATA].get(self._thing.name, None)
if status:
Expand All @@ -79,10 +81,10 @@ def state(self):
@property
def device_class(self):
"""Return the device class."""
return DEVICE_CLASS_HUMIDITY
return SensorDeviceClass.HUMIDITY

@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return PERCENTAGE

Expand All @@ -101,7 +103,7 @@ def name(self):
return f"{self._thing.name} PM2.5"

@property
def state(self):
def native_value(self):
"""Return the PM2.5 value."""
status = self.hass.data[DOMAIN][UPDATED_DATA].get(self._thing.name, None)
if status:
Expand All @@ -111,10 +113,10 @@ def state(self):
@property
def device_class(self):
"""Return the device class."""
return DEVICE_CLASS_PM25
return SensorDeviceClass.PM25

@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return CONCENTRATION_MICROGRAMS_PER_CUBIC_METER

Expand All @@ -133,7 +135,7 @@ def name(self):
return f"{self._thing.name} Odor Level"

@property
def state(self):
def native_value(self):
"""Return the odor level."""
status = self.hass.data[DOMAIN][UPDATED_DATA].get(self._thing.name, None)
if status:
Expand All @@ -144,6 +146,16 @@ def state(self):
elif status.odor_level == "high":
return ODOR_LEVEL_HIGH
return None

@property
def options(self):
"""Return all odor levels."""
return ODOR_LEVELS

@property
def device_class(self):
"""Return the device class."""
return SensorDeviceClass.ENUM

@property
def unique_id(self):
Expand All @@ -160,7 +172,7 @@ def name(self):
return f"{self._thing.name} Power Consumption"

@property
def state(self):
def native_value(self):
"""Return the power consumption in KW/H"""
status = self.hass.data[DOMAIN][UPDATED_DATA].get(self._thing.name, None)
if status:
Expand All @@ -170,12 +182,12 @@ def state(self):
@property
def device_class(self):
"""Return the device class."""
return DEVICE_CLASS_ENERGY
return SensorDeviceClass.ENERGY

@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return ENERGY_KILO_WATT_HOUR
return UnitOfEnergy.KILO_WATT_HOUR

@property
def unique_id(self):
Expand All @@ -195,7 +207,7 @@ def name(self):
return f"{self._thing.name} Monthly Power Consumption"

@property
def state(self):
def native_value(self):
"""Return the monthly power consumption in KW/H"""
monthly_data = self._thing.monthly_data
if monthly_data:
Expand All @@ -205,12 +217,12 @@ def state(self):
@property
def device_class(self):
"""Return the device class."""
return DEVICE_CLASS_ENERGY
return SensorDeviceClass.ENERGY

@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return ENERGY_KILO_WATT_HOUR
return UnitOfEnergy.KILO_WATT_HOUR

@property
def unique_id(self):
Expand Down Expand Up @@ -248,7 +260,7 @@ def native_value(self):
@property
def device_class(self):
"""Return the device class."""
return DEVICE_CLASS_DATE
return SensorDeviceClass.DATE

@property
def unique_id(self):
Expand All @@ -265,7 +277,7 @@ def name(self):
return f"{self._thing.name} Indoor Temperature"

@property
def state(self):
def native_value(self):
"""Return the indoor temperature."""
status = self.hass.data[DOMAIN][UPDATED_DATA].get(self._thing.name, None)
if status:
Expand All @@ -275,12 +287,12 @@ def state(self):
@property
def device_class(self):
"""Return the device class."""
return DEVICE_CLASS_TEMPERATURE
return SensorDeviceClass.TEMPERATURE

@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

@property
def unique_id(self):
Expand Down

0 comments on commit 3ff38d6

Please sign in to comment.