Skip to content

Commit

Permalink
Synchronize code with source #3 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
pokornyIt authored Jan 11, 2025
1 parent 87aa995 commit c31aaf1
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 31 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Supported humidifiers:
* Dual200S
* LUH-D301S-WEU

# Changes 2025-01-11

- update top on original from 2024-11-05

# Changes 2022-12-13

- add support for HACS
Expand Down
20 changes: 8 additions & 12 deletions custom_components/vesync_formatbce/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ async def async_setup_entry(hass, config_entry):

device_dict = await async_process_devices(hass, manager)

forward_setup = hass.config_entries.async_forward_entry_setup

hass.data[DOMAIN] = {}
hass.data[DOMAIN][VS_MANAGER] = manager

Expand All @@ -96,20 +94,19 @@ async def async_setup_entry(hass, config_entry):

if device_dict[VS_SWITCHES]:
switches.extend(device_dict[VS_SWITCHES])
hass.async_create_task(forward_setup(config_entry, "switch"))
await hass.config_entries.async_forward_entry_setups(config_entry, ["switch"])

if device_dict[VS_FANS]:
fans.extend(device_dict[VS_FANS])
hass.async_create_task(forward_setup(config_entry, "fan"))
await hass.config_entries.async_forward_entry_setups(config_entry, ["fan"])

if device_dict[VS_HUMIDIFIERS]:
humidifiers.extend(device_dict[VS_HUMIDIFIERS])
hass.async_create_task(forward_setup(config_entry, "humidifier"))
hass.async_create_task(forward_setup(config_entry, "sensor"))
await hass.config_entries.async_forward_entry_setups(config_entry, ["sensor", "humidifier"])

if device_dict[VS_LIGHTS]:
lights.extend(device_dict[VS_LIGHTS])
hass.async_create_task(forward_setup(config_entry, "light"))
await hass.config_entries.async_forward_entry_setups(config_entry, ["light"])

async def async_new_device_discovery(service):
"""Discover if new devices should be added."""
Expand All @@ -133,7 +130,7 @@ async def async_new_device_discovery(service):
return
if new_switches and not switches:
switches.extend(new_switches)
hass.async_create_task(forward_setup(config_entry, "switch"))
await hass.config_entries.async_forward_entry_setups(config_entry, ["switch"])

fan_set = set(fan_devs)
new_fans = list(fan_set.difference(fans))
Expand All @@ -143,7 +140,7 @@ async def async_new_device_discovery(service):
return
if new_fans and not fans:
fans.extend(new_fans)
hass.async_create_task(forward_setup(config_entry, "fan"))
await hass.config_entries.async_forward_entry_setups(config_entry, ["fan"])

humidifier_set = set(humidifier_devs)
new_humidifiers = list(humidifier_set.difference(humidifiers))
Expand All @@ -153,8 +150,7 @@ async def async_new_device_discovery(service):
return
if new_humidifiers and not humidifiers:
humidifiers.extend(new_humidifiers)
hass.async_create_task(forward_setup(config_entry, "humidifier"))
hass.async_create_task(forward_setup(config_entry, "sensor"))
await hass.config_entries.async_forward_entry_setups(config_entry, ["sensor", "humidifier"])

light_set = set(light_devs)
new_lights = list(light_set.difference(lights))
Expand All @@ -164,7 +160,7 @@ async def async_new_device_discovery(service):
return
if new_lights and not lights:
lights.extend(new_lights)
hass.async_create_task(forward_setup(config_entry, "light"))
await hass.config_entries.async_forward_entry_setups(config_entry, ["light"])

hass.services.async_register(
DOMAIN, SERVICE_UPDATE_DEVS, async_new_device_discovery
Expand Down
1 change: 1 addition & 0 deletions custom_components/vesync_formatbce/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
HUMI_PROPS = {
"Classic300S": [VS_HUMIDIFIERS, VS_SWITCHES, VS_LIGHTS],
"Dual200S": [VS_HUMIDIFIERS, VS_SWITCHES],
"LUH-D301S-WEU": [VS_HUMIDIFIERS, VS_SWITCHES],
}


Expand Down
13 changes: 8 additions & 5 deletions custom_components/vesync_formatbce/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import math
from typing import List

from homeassistant.components.fan import SUPPORT_SET_SPEED, FanEntity
from homeassistant.components.fan import (
FanEntity,
FanEntityFeature,
)
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.util.percentage import (
Expand Down Expand Up @@ -68,15 +71,15 @@ def _async_setup_entities(devices: List[CoordinatedVeSyncDevice], async_add_enti
class VeSyncFanHA(ToggleVeSyncEntity, FanEntity):
"""Representation of a VeSync fan."""

def __init__(self, fan: CoordinatedVeSyncDevice):
def __init__(self, wrapper: CoordinatedVeSyncDevice):
"""Initialize the VeSync fan device."""
super().__init__(fan)
self.smartfan = fan
super().__init__(wrapper)
self.smartfan = wrapper.device

@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_SET_SPEED
return FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE

@property
def percentage(self):
Expand Down
12 changes: 7 additions & 5 deletions custom_components/vesync_formatbce/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import math
from typing import List

from homeassistant.components.humidifier import HumidifierEntity
from homeassistant.components.humidifier import (
HumidifierEntity,
HumidifierDeviceClass,
)
from homeassistant.components.humidifier.const import (
DEVICE_CLASS_HUMIDIFIER,
MODE_AUTO,
MODE_SLEEP,
SUPPORT_MODES,
HumidifierEntityFeature,
)
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
Expand Down Expand Up @@ -76,7 +78,7 @@ def available_modes(self):
@property
def device_class(self):
"""Return the device class type."""
return DEVICE_CLASS_HUMIDIFIER
return HumidifierDeviceClass.HUMIDIFIER

@property
def max_humidity(self):
Expand All @@ -92,7 +94,7 @@ def min_humidity(self):
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_MODES
return HumidifierEntityFeature.MODES

@property
def mode(self):
Expand Down
5 changes: 2 additions & 3 deletions custom_components/vesync_formatbce/manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"domain": "vesync_formatbce",
"name": "VeSync-FormatBCE",
"version": "1.0.2",
"version": "1.0.4",
"documentation": "https://www.home-assistant.io/integrations/vesync",
"issue_tracker": "https://github.com/pokornyIt/HA_VeSync_Classic300s/issues",
"codeowners": ["@markperdue", "@webdjoe", "@thegardenmonkey", "@formatBCE", "@pokornyIt"],
"codeowners": ["@markperdue", "@webdjoe", "@thegardenmonkey", "@formatBCE"],
"requirements": ["pyvesync==1.4.3"],
"config_flow": true,
"iot_class": "cloud_polling"
Expand Down
10 changes: 5 additions & 5 deletions custom_components/vesync_formatbce/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import List

from homeassistant.components.binary_sensor import BinarySensorDeviceClass, BinarySensorEntity
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
from homeassistant.const import DEVICE_CLASS_HUMIDITY, PERCENTAGE
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass, SensorEntity
from homeassistant.const import PERCENTAGE
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect

Expand Down Expand Up @@ -56,8 +56,8 @@ def _async_setup_entities(devices: List[CoordinatedVeSyncDevice], async_add_enti
class VeSyncHumiditySensorHA(VeSyncEntity, SensorEntity):
"""Representation of a VeSync humidity sensor."""

_attr_device_class = DEVICE_CLASS_HUMIDITY
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_device_class = SensorDeviceClass.HUMIDITY
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = PERCENTAGE

@property
Expand Down Expand Up @@ -196,4 +196,4 @@ def is_on(self):
)
return False
# convert percent brightness to ha expected range
return humidity_high
return humidity_high
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"fan",
"humidifier"
],
"homeassistant": "2022.10.0"
"homeassistant": "2024.10.0"
}

0 comments on commit c31aaf1

Please sign in to comment.