Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Remove local pyvesync lib and migrate to public one. (#25)
Browse files Browse the repository at this point in the history
* move to pip pyvesync library

* remove pyvesync

* improve extra attributes

* fix style
  • Loading branch information
vlebourl authored Jun 8, 2022
1 parent 4f3c7fd commit d10928e
Show file tree
Hide file tree
Showing 24 changed files with 29 additions and 3,423 deletions.
2 changes: 1 addition & 1 deletion custom_components/vesync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send
from pyvesync.vesync import VeSync

from .common import async_process_devices
from .const import (
Expand All @@ -21,7 +22,6 @@
VS_SENSORS,
VS_SWITCHES,
)
from .pyvesync.vesync import VeSync

PLATFORMS = {
Platform.SWITCH: VS_SWITCHES,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/vesync/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from homeassistant.helpers.entity import Entity, ToggleEntity
from pyvesync.vesyncfan import model_features

from .const import (
DOMAIN,
Expand All @@ -13,7 +14,6 @@
VS_SENSORS,
VS_SWITCHES,
)
from .pyvesync.vesyncfan import model_features

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/vesync/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
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
from .pyvesync.vesync import VeSync

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 2 additions & 0 deletions custom_components/vesync/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
VS_MODE_AUTO = "auto"
VS_MODE_MANUAL = "manual"

VS_TO_HA_ATTRIBUTES = {"humidity": "current_humidity"}

DEV_TYPE_TO_HA = {
"Core200S": "fan",
"Core300S": "fan",
Expand Down
31 changes: 8 additions & 23 deletions custom_components/vesync/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

from .common import VeSyncDevice
from .const import DEV_TYPE_TO_HA, DOMAIN, VS_DISCOVERY, VS_FANS
from .const import DEV_TYPE_TO_HA, DOMAIN, VS_DISCOVERY, VS_FANS, VS_TO_HA_ATTRIBUTES

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -114,28 +114,13 @@ def unique_info(self):
def extra_state_attributes(self):
"""Return the state attributes of the fan."""
attr = {}

if hasattr(self.smartfan, "active_time"):
attr["active_time"] = self.smartfan.active_time

if hasattr(self.smartfan, "screen_status"):
attr["screen_status"] = self.smartfan.screen_status

if hasattr(self.smartfan, "child_lock"):
attr["child_lock"] = self.smartfan.child_lock

if hasattr(self.smartfan, "night_light"):
attr["night_light"] = self.smartfan.night_light

if hasattr(self.smartfan, "air_quality"):
attr["air_quality"] = self.smartfan.air_quality

if hasattr(self.smartfan, "mode"):
attr["mode"] = self.smartfan.mode

if hasattr(self.smartfan, "filter_life"):
attr["filter_life"] = self.smartfan.filter_life

for k, v in self.smarthumidifier.details.items():
if k in VS_TO_HA_ATTRIBUTES:
attr[VS_TO_HA_ATTRIBUTES[k]] = v
elif k in self.state_attributes:
attr[f"vs_{k}"] = v
else:
attr[k] = v
return attr

def set_percentage(self, percentage):
Expand Down
18 changes: 13 additions & 5 deletions custom_components/vesync/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .common import VeSyncDevice, is_humidifier
from .const import DOMAIN, VS_DISCOVERY, VS_HUMIDIFIERS, VS_MODE_AUTO, VS_MODE_MANUAL
from .const import (
DOMAIN,
VS_DISCOVERY,
VS_HUMIDIFIERS,
VS_MODE_AUTO,
VS_MODE_MANUAL,
VS_TO_HA_ATTRIBUTES,
)

_LOGGER = logging.getLogger(__name__)

MAX_HUMIDITY = 80
MIN_HUMIDITY = 30

MODES = [MODE_AUTO, MODE_NORMAL, MODE_SLEEP]
VESYNC_TO_HA_ATTRIBUTES = {"humidity": "current_humidity"}


async def async_setup_entry(
Expand Down Expand Up @@ -117,9 +123,11 @@ def extra_state_attributes(self):

attr = {}
for k, v in self.smarthumidifier.details.items():
if k in VESYNC_TO_HA_ATTRIBUTES:
attr[VESYNC_TO_HA_ATTRIBUTES[k]] = v
elif k not in self.state_attributes:
if k in VS_TO_HA_ATTRIBUTES:
attr[VS_TO_HA_ATTRIBUTES[k]] = v
elif k in self.state_attributes:
attr[f"vs_{k}"] = v
else:
attr[k] = v
return attr

Expand Down
6 changes: 0 additions & 6 deletions custom_components/vesync/pyvesync/__init__.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
241 changes: 0 additions & 241 deletions custom_components/vesync/pyvesync/helpers.py

This file was deleted.

Loading

0 comments on commit d10928e

Please sign in to comment.