Skip to content

Commit

Permalink
Merge pull request #16 from micahqcade/main
Browse files Browse the repository at this point in the history
Update from upstream
  • Loading branch information
gdgib committed May 24, 2024
2 parents 636eb82 + 2757cb3 commit 1069ae2
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 53 deletions.
10 changes: 6 additions & 4 deletions custom_components/vesync/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""VeSync integration."""
import logging

from datetime import timedelta
import logging

from pyvesync.vesync import VeSync

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from pyvesync.vesync import VeSync

from .common import async_process_devices
from .const import (
Expand Down Expand Up @@ -68,7 +70,7 @@ async def async_update_data():
try:
await hass.async_add_executor_job(manager.update)
except Exception as err:
raise UpdateFailed(f"Update failed: {err}")
raise UpdateFailed(f"Update failed: {err}") from err

coordinator = DataUpdateCoordinator(
hass,
Expand Down Expand Up @@ -111,7 +113,7 @@ def _add_new_devices(platform: str) -> None:
else:
hass.async_create_task(forward_setup(config_entry, platform))

for k, v in PLATFORMS.items():
for k in PLATFORMS:
_add_new_devices(k)

hass.services.async_register(
Expand Down
6 changes: 3 additions & 3 deletions custom_components/vesync/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for power & energy sensors for VeSync outlets."""

import logging

from homeassistant.components.binary_sensor import BinarySensorEntity
Expand Down Expand Up @@ -46,7 +47,7 @@ def _setup_entities(devices, async_add_entities, coordinator):
for dev in devices:
if hasattr(dev, "fryer_status"):
for stype in BINARY_SENSOR_TYPES_AIRFRYER.values():
entities.append(
entities.append( # noqa: PERF401
VeSyncairfryerSensor(
dev,
coordinator,
Expand Down Expand Up @@ -88,8 +89,7 @@ def name(self):
@property
def is_on(self) -> bool:
"""Return a value indicating whether the Humidifier's water tank is lifted."""
value = getattr(self.airfryer, self.stype[0], None)
return value
return getattr(self.airfryer, self.stype[0], None)
# return self.smarthumidifier.details["water_tank_lifted"]

@property
Expand Down
3 changes: 2 additions & 1 deletion custom_components/vesync/button.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for VeSync button."""

import logging

from homeassistant.components.button import ButtonEntity
Expand Down Expand Up @@ -55,7 +56,7 @@ def _setup_entities(devices, async_add_entities, coordinator):
for dev in devices:
if hasattr(dev, "cook_set_temp"):
for stype in SENSOR_TYPES_CS158.values():
entities.append(
entities.append( # noqa: PERF401
VeSyncairfryerButton(
dev,
coordinator,
Expand Down
7 changes: 4 additions & 3 deletions custom_components/vesync/common.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Common utilities for VeSync Component."""
import logging

from pyvesync.vesyncfan import model_features as fan_model_features
from pyvesync.vesynckitchen import model_features as kitchen_model_features

from homeassistant.components.diagnostics import async_redact_data
from homeassistant.helpers.entity import Entity, ToggleEntity
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from pyvesync.vesyncfan import model_features as fan_model_features
from pyvesync.vesynckitchen import model_features as kitchen_model_features

from .const import (
DOMAIN,
Expand Down Expand Up @@ -104,7 +105,7 @@ async def async_process_devices(hass, manager):
in VS_AIRFRYER_TYPES
):
_LOGGER.warning(
"Found air fryer %s, support in progress.\n%s", airfryer.device_name
"Found air fryer %s, support in progress.\n", airfryer.device_name
)
devices[VS_SENSORS].append(airfryer)
devices[VS_BINARY_SENSORS].append(airfryer)
Expand Down
5 changes: 3 additions & 2 deletions custom_components/vesync/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""Config flow utilities."""
import logging
from collections import OrderedDict
import logging

from pyvesync.vesync import VeSync
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.components import dhcp
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from pyvesync.vesync import VeSync

from .const import DOMAIN

Expand Down
23 changes: 12 additions & 11 deletions custom_components/vesync/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Constants for VeSync Component."""

from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, TIME_MINUTES
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import UnitOfTemperature, UnitOfTime

DOMAIN = "vesync"
VS_DISCOVERY = "vesync_discovery_{}"
Expand Down Expand Up @@ -72,33 +73,33 @@
"current_temp": [
"current_temperature",
"Current temperature",
TEMP_CELSIUS,
UnitOfTemperature.CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
SensorDeviceClass.TEMPERATURE,
"current_temp",
],
"cook_set_temp": [
"set_temperature",
"Set temperature",
TEMP_CELSIUS,
UnitOfTemperature.CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
SensorDeviceClass.TEMPERATURE,
"cook_set_temp",
],
"cook_last_time": [
"cook_last_time",
"Cook Remaining",
TIME_MINUTES,
UnitOfTime.MINUTES,
"mdi:timer",
TIME_MINUTES,
UnitOfTime.MINUTES,
"cook_last_time",
],
"preheat_last_time": [
"preheat_last_time",
"Preheat Remaining",
TIME_MINUTES,
UnitOfTime.MINUTES,
"mdi:timer",
TIME_MINUTES,
UnitOfTime.MINUTES,
"preheat_last_time",
],
"cook_status": [
Expand All @@ -112,9 +113,9 @@
# "remaining_time": [
# "remaining_time",
# "running:",
# TIME_MINUTES,
# UnitOfTime.MINUTES,
# "mdi:timer",
# TIME_MINUTES,
# UnitOfTime.MINUTES,
# "remaining_time",
# ],
}
9 changes: 5 additions & 4 deletions custom_components/vesync/device_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import logging

import homeassistant.helpers.config_validation as cv
import voluptuous as vol

from homeassistant.components.device_automation import toggle_entity
from homeassistant.const import (
ATTR_ENTITY_ID,
Expand All @@ -16,7 +16,8 @@
)
from homeassistant.core import Context, HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry
from homeassistant.helpers import entity_registry as er
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import get_capability
from homeassistant.helpers.typing import ConfigType, TemplateVarsType

Expand All @@ -41,11 +42,11 @@ async def async_get_actions(
hass: HomeAssistant, device_id: str
) -> list[dict[str, str]]:
"""List device actions for Humidifier devices."""
registry = entity_registry.async_get(hass)
registry = er.async_get(hass)
actions = await toggle_entity.async_get_actions(hass, device_id, DOMAIN)

# Get all the integrations entities for this device
for entry in entity_registry.async_entries_for_device(registry, device_id):
for entry in er.async_entries_for_device(registry, device_id):
if entry.domain != "fan":
continue

Expand Down
7 changes: 4 additions & 3 deletions custom_components/vesync/fan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for VeSync fans."""

import math

from homeassistant.components.fan import FanEntity, FanEntityFeature
Expand Down Expand Up @@ -165,9 +166,9 @@ def set_preset_mode(self, preset_mode):

def turn_on(
self,
speed: str = None,
percentage: int = None,
preset_mode: str = None,
# speed: str | None = None,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs,
) -> None:
"""Turn the device on."""
Expand Down
10 changes: 6 additions & 4 deletions custom_components/vesync/humidifier.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
"""Support for VeSync humidifiers."""
from __future__ import annotations

from collections.abc import Mapping
import logging
from typing import Any, Mapping
from typing import Any

from pyvesync.vesyncfan import VeSyncHumid200300S

from homeassistant.components.humidifier import HumidifierEntity
from homeassistant.components.humidifier.const import (
MODE_AUTO,
MODE_NORMAL,
MODE_SLEEP,
SUPPORT_MODES,
HumidifierEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from pyvesync.vesyncfan import VeSyncHumid200300S

from .common import VeSyncDevice
from .const import (
Expand Down Expand Up @@ -122,7 +124,7 @@ def available_modes(self) -> list[str]:
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_MODES
return HumidifierEntityFeature.MODES

@property
def target_humidity(self) -> int:
Expand Down
20 changes: 14 additions & 6 deletions custom_components/vesync/manifest.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
{
"domain": "vesync",
"name": "VeSync",
"codeowners": ["@markperdue", "@webdjoe", "@thegardenmonkey", "@vlebourl","@tv4you2016"],
"codeowners": [
"@markperdue",
"@webdjoe",
"@thegardenmonkey",
"@vlebourl",
"@tv4you2016"
],
"config_flow": true,
"dhcp": [
{
"hostname": "levoit-*",
"macaddress": "*"
}
],
"documentation": "https://www.home-assistant.io/integrations/vesync",
"documentation": "https://github.com/AndreaTomatis/custom_vesync",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/vlebourl/custom_vesync",
"requirements": ["pyvesync==2.1.10"],
"version": "1.3.0"
}
"issue_tracker": "https://github.com/AndreaTomatis/custom_vesync",
"requirements": [
"pyvesync==2.1.10"
],
"version": "1.3.1"
}
3 changes: 1 addition & 2 deletions custom_components/vesync/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ def native_unit_of_measurement(self):

@property
def device_class(self):
"""
Return the device class of the target humidity level.
"""Return the device class of the target humidity level.
Eventually this should become NumberDeviceClass but that was introduced in 2022.12.
For maximum compatibility, using SensorDeviceClass as recommended by deprecation notice.
Expand Down
20 changes: 10 additions & 10 deletions custom_components/vesync/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for power & energy sensors for VeSync outlets."""

import logging

from homeassistant.components.sensor import (
Expand All @@ -7,7 +8,7 @@
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENERGY_KILO_WATT_HOUR, PERCENTAGE, POWER_WATT
from homeassistant.const import PERCENTAGE, UnitOfEnergy, UnitOfPower
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
Expand Down Expand Up @@ -57,7 +58,7 @@ def _setup_entities(devices, async_add_entities, coordinator):
for dev in devices:
if hasattr(dev, "fryer_status"):
for stype in SENSOR_TYPES_AIRFRYER.values():
entities.append(
entities.append( # noqa: PERF401
VeSyncairfryerSensor(
dev,
coordinator,
Expand Down Expand Up @@ -111,8 +112,7 @@ def device_class(self):
@property
def native_value(self):
"""Return the value."""
value = getattr(self.airfryer, self.stype[5], None)
return value
return getattr(self.airfryer, self.stype[5], None)

@property
def native_unit_of_measurement(self):
Expand Down Expand Up @@ -170,7 +170,7 @@ def native_value(self):
@property
def native_unit_of_measurement(self):
"""Return the Watt unit of measurement."""
return POWER_WATT
return UnitOfPower.WATT

@property
def state_class(self):
Expand Down Expand Up @@ -214,7 +214,7 @@ def native_value(self):
@property
def native_unit_of_measurement(self):
"""Return the kWh unit of measurement."""
return ENERGY_KILO_WATT_HOUR
return UnitOfEnergy.KILO_WATT_HOUR

@property
def state_class(self):
Expand Down Expand Up @@ -276,12 +276,12 @@ def native_value(self):
quality = self.smarthumidifier.details["air_quality"]
if isinstance(quality, (int, float)):
return quality
_LOGGER.warn(
_LOGGER.warning(
"Got non numeric value for AQI sensor from 'air_quality' for %s: %s",
self.name,
quality,
)
_LOGGER.warn("No air quality index found in '%s'", self.name)
_LOGGER.warning("No air quality index found in '%s'", self.name)
return None


Expand Down Expand Up @@ -313,12 +313,12 @@ def native_value(self):
quality_value = self.smarthumidifier.details["air_quality_value"]
if isinstance(quality_value, (int, float)):
return quality_value
_LOGGER.warn(
_LOGGER.warning(
"Got non numeric value for AQI sensor from 'air_quality_value' for %s: %s",
self.name,
quality_value,
)
_LOGGER.warn("No air quality value found in '%s'", self.name)
_LOGGER.warning("No air quality value found in '%s'", self.name)
return None


Expand Down

0 comments on commit 1069ae2

Please sign in to comment.