Skip to content

Commit

Permalink
Add entities only if supported
Browse files Browse the repository at this point in the history
  • Loading branch information
nbogojevic committed Dec 22, 2021
1 parent 0fd854d commit c37b448
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
4 changes: 3 additions & 1 deletion custom_components/midea_dehumidifier_lan/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ async def async_setup_entry(
"""Sets up full tank binary sensors"""
hub: Hub = hass.data[DOMAIN][config_entry.entry_id]

async_add_entities(TankFullSensor(coordinator) for coordinator in hub.coordinators)
async_add_entities(
TankFullSensor(c) for c in hub.coordinators if c.is_dehumidifier()
)


class TankFullSensor(ApplianceEntity, BinarySensorEntity):
Expand Down
17 changes: 14 additions & 3 deletions custom_components/midea_dehumidifier_lan/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@
DOMAIN: Final = "midea_dehumidifier_lan"
ISSUE_URL: Final = "https://github.com/nbogojevic/midea-dehumidifier-lan/issues"

CONF_APP: Final = "mobile_app"
CONF_TOKEN_KEY: Final = "token_key"
CONF_ADVANCED_OPTIONS: Final = "advanced_options"
CONF_APPID: Final = "appid"
CONF_APPKEY: Final = "appkey"
CONF_IGNORE_APPLIANCE: Final = "ignore_appliance"
CONF_MOBILE_APP: Final = "mobile_app"
CONF_NETWORK_RANGE: Final = "network_range"
CONF_TOKEN_KEY: Final = "token_key"

TAG_CAUSE: Final = "cause"
TAG_ID: Final = "id"
TAG_INTEGRATION: Final = "integration_name"
TAG_NAME: Final = "name"

MAX_TARGET_HUMIDITY: Final = 85
MIN_TARGET_HUMIDITY: Final = 35

PLATFORMS: Final = [
Platform.FAN,
Expand All @@ -26,7 +38,6 @@

IGNORED_IP_ADDRESS: Final = "0.0.0.0"


DEFAULT_APP: Final = "NetHome"

DEFAULT_USERNAME: Final = ""
Expand Down
4 changes: 3 additions & 1 deletion custom_components/midea_dehumidifier_lan/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ async def async_setup_entry(

hub: Hub = hass.data[DOMAIN][config_entry.entry_id]

async_add_entities(DehumidiferFan(coordinator) for coordinator in hub.coordinators)
async_add_entities(
DehumidiferFan(c) for c in hub.coordinators if c.is_dehumidifier()
)


class DehumidiferFan(ApplianceEntity, FanEntity):
Expand Down
22 changes: 13 additions & 9 deletions custom_components/midea_dehumidifier_lan/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from custom_components.midea_dehumidifier_lan import ApplianceEntity, Hub
from custom_components.midea_dehumidifier_lan.const import DOMAIN
from custom_components.midea_dehumidifier_lan.const import (
DOMAIN,
MAX_TARGET_HUMIDITY,
MIN_TARGET_HUMIDITY,
)

_LOGGER = logging.getLogger(__name__)
AVAILABLE_MODES = [MODE_AUTO, MODE_NORMAL, MODE_BOOST, MODE_COMFORT]
Expand All @@ -30,7 +34,7 @@ async def async_setup_entry(
hub: Hub = hass.data[DOMAIN][config_entry.entry_id]

async_add_entities(
DehumidifierEntity(coordinator) for coordinator in hub.coordinators
DehumidifierEntity(c) for c in hub.coordinators if c.is_dehumidifier()
)


Expand All @@ -49,7 +53,7 @@ def unique_id_prefix(self) -> str:

@property
def is_on(self):
return getattr(self.appliance.state, "is_on", False)
return getattr(self.appliance.state, "running", False)

@property
def device_class(self):
Expand Down Expand Up @@ -83,22 +87,22 @@ def mode(self):

@property
def min_humidity(self):
"""Return the min humidity set."""
return 40
"""Return the min humidity that can be set."""
return MIN_TARGET_HUMIDITY

@property
def max_humidity(self):
"""Return the max humidity set."""
return 85
"""Return the max humidity that can be set."""
return MAX_TARGET_HUMIDITY

def turn_on(self, **kwargs):
"""Turn the entity on."""
setattr(self.appliance.state, "is_on", True)
setattr(self.appliance.state, "running", True)
self.appliance.apply()

def turn_off(self, **kwargs):
"""Turn the entity off."""
setattr(self.appliance.state, "is_on", False)
setattr(self.appliance.state, "running", False)
self.appliance.apply()

def set_mode(self, mode):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/midea_dehumidifier_lan/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def async_setup_entry(

hub: Hub = hass.data[DOMAIN][config_entry.entry_id]

async_add_entities(IonSwitch(coordinator) for coordinator in hub.coordinators)
async_add_entities(IonSwitch(c) for c in hub.coordinators if c.is_dehumidifier())


class IonSwitch(ApplianceEntity, SwitchEntity):
Expand Down

0 comments on commit c37b448

Please sign in to comment.