Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion custom_components/smartthings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import async_get_loaded_integration
from homeassistant.setup import SetupPhases, async_pause_setup

from .config_flow import SmartThingsFlowHandler # noqa: F401
from .const import (
Expand Down Expand Up @@ -154,7 +156,13 @@ async def retrieve_device_status(device):
)

# Setup device broker
broker = DeviceBroker(hass, entry, token, smart_app, devices, scenes)
with async_pause_setup(hass, SetupPhases.WAIT_IMPORT_PLATFORMS):
# DeviceBroker has a side effect of importing platform
# modules when its created. In the future this should be
# refactored to not do this.
broker = await hass.async_add_import_executor_job(
DeviceBroker, hass, entry, token, smart_app, devices, scenes
)
broker.connect()
hass.data[DOMAIN][DATA_BROKERS][entry.entry_id] = broker

Expand Down
39 changes: 16 additions & 23 deletions custom_components/smartthings/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@
import asyncio

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_DOOR,
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_MOVING,
DEVICE_CLASS_OPENING,
DEVICE_CLASS_PRESENCE,
DEVICE_CLASS_PROBLEM,
DEVICE_CLASS_SOUND,
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
from homeassistant.const import EntityCategory

from . import SmartThingsEntity
from .const import DATA_BROKERS, DOMAIN
Expand All @@ -37,18 +30,18 @@
Capability.water_sensor: Attribute.water,
}
ATTRIB_TO_CLASS = {
Attribute.acceleration: DEVICE_CLASS_MOVING,
Attribute.contact: DEVICE_CLASS_OPENING,
Attribute.filter_status: DEVICE_CLASS_PROBLEM,
Attribute.motion: DEVICE_CLASS_MOTION,
Attribute.presence: DEVICE_CLASS_PRESENCE,
Attribute.sound: DEVICE_CLASS_SOUND,
Attribute.tamper: DEVICE_CLASS_PROBLEM,
Attribute.valve: DEVICE_CLASS_OPENING,
Attribute.water: DEVICE_CLASS_MOISTURE,
Attribute.acceleration: BinarySensorDeviceClass.MOVING,
Attribute.contact: BinarySensorDeviceClass.OPENING,
Attribute.filter_status: BinarySensorDeviceClass.PROBLEM,
Attribute.motion: BinarySensorDeviceClass.MOTION,
Attribute.presence: BinarySensorDeviceClass.PRESENCE,
Attribute.sound: BinarySensorDeviceClass.SOUND,
Attribute.tamper: BinarySensorDeviceClass.PROBLEM,
Attribute.valve: BinarySensorDeviceClass.OPENING,
Attribute.water: BinarySensorDeviceClass.MOISTURE,
}
ATTRIB_TO_ENTTIY_CATEGORY = {
Attribute.tamper: ENTITY_CATEGORY_DIAGNOSTIC,
Attribute.tamper: EntityCategory.DIAGNOSTIC,
}


Expand All @@ -75,7 +68,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
SamsungCooktopBurner(device, "Cooktop Bottom Right", 16),
]
)
elif model in ("21K_REF_LCD_FHUB6.0", "ARTIK051_REF_17K"):
elif model in ("21K_REF_LCD_FHUB6.0", "ARTIK051_REF_17K","TP1X_REF_21K"):
sensors.extend(
[
SamsungOcfDoorBinarySensor(
Expand All @@ -84,23 +77,23 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"/door/cooler/0",
"Open",
"Closed",
DEVICE_CLASS_DOOR,
BinarySensorDeviceClass.DOOR,
),
SamsungOcfDoorBinarySensor(
device,
"Freezer Door",
"/door/freezer/0",
"Open",
"Closed",
DEVICE_CLASS_DOOR,
BinarySensorDeviceClass.DOOR,
),
SamsungOcfDoorBinarySensor(
device,
"FlexZone Door",
"/door/cvroom/0",
"Open",
"Closed",
DEVICE_CLASS_DOOR,
BinarySensorDeviceClass.DOOR,
),
]
)
Expand Down
124 changes: 55 additions & 69 deletions custom_components/smartthings/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,8 @@
ATTR_HVAC_MODE,
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
CURRENT_HVAC_COOL,
CURRENT_HVAC_FAN,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
HVAC_MODE_OFF,
SUPPORT_FAN_MODE,
SUPPORT_SWING_MODE,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_TARGET_TEMPERATURE_RANGE,
SUPPORT_PRESET_MODE,
HVACAction,
HVACMode,
)
from homeassistant.const import ATTR_TEMPERATURE

Expand All @@ -36,50 +22,50 @@

ATTR_OPERATION_STATE = "operation_state"
MODE_TO_STATE = {
"auto": HVAC_MODE_HEAT_COOL,
"cool": HVAC_MODE_COOL,
"eco": HVAC_MODE_AUTO,
"rush hour": HVAC_MODE_AUTO,
"emergency heat": HVAC_MODE_HEAT,
"heat": HVAC_MODE_HEAT,
"off": HVAC_MODE_OFF,
"wind": HVAC_MODE_FAN_ONLY,
"auto": HVACMode.HEAT_COOL,
"cool": HVACMode.COOL,
"eco": HVACMode.AUTO,
"rush hour": HVACMode.AUTO,
"emergency heat": HVACMode.HEAT,
"heat": HVACMode.HEAT,
"off": HVACMode.OFF,
"wind": HVACMode.FAN_ONLY,
}
STATE_TO_MODE = {
HVAC_MODE_HEAT_COOL: "auto",
HVAC_MODE_COOL: "cool",
HVAC_MODE_HEAT: "heat",
HVAC_MODE_OFF: "off",
HVAC_MODE_FAN_ONLY: "wind",
HVACMode.HEAT_COOL: "auto",
HVACMode.COOL: "cool",
HVACMode.HEAT: "heat",
HVACMode.OFF: "off",
HVACMode.FAN_ONLY: "wind",
}

OPERATING_STATE_TO_ACTION = {
"cooling": CURRENT_HVAC_COOL,
"fan only": CURRENT_HVAC_FAN,
"heating": CURRENT_HVAC_HEAT,
"idle": CURRENT_HVAC_IDLE,
"pending cool": CURRENT_HVAC_COOL,
"pending heat": CURRENT_HVAC_HEAT,
"vent economizer": CURRENT_HVAC_FAN,
"cooling": HVACAction.COOLING,
"fan only": HVACAction.FAN,
"heating": HVACAction.HEATING,
"idle": HVACAction.IDLE,
"pending cool": HVACAction.COOLING,
"pending heat": HVACAction.HEATING,
"vent economizer": HVACAction.FAN,
}

AC_MODE_TO_STATE = {
"auto": HVAC_MODE_HEAT_COOL,
"cool": HVAC_MODE_COOL,
"dry": HVAC_MODE_DRY,
"coolClean": HVAC_MODE_COOL,
"dryClean": HVAC_MODE_DRY,
"heat": HVAC_MODE_HEAT,
"heatClean": HVAC_MODE_HEAT,
"fanOnly": HVAC_MODE_FAN_ONLY,
"wind": HVAC_MODE_FAN_ONLY,
"auto": HVACMode.HEAT_COOL,
"cool": HVACMode.COOL,
"dry": HVACMode.DRY,
"coolClean": HVACMode.COOL,
"dryClean": HVACMode.DRY,
"heat": HVACMode.HEAT,
"heatClean": HVACMode.HEAT,
"fanOnly": HVACMode.FAN_ONLY,
"wind": HVACMode.FAN_ONLY,
}
STATE_TO_AC_MODE = {
HVAC_MODE_HEAT_COOL: "auto",
HVAC_MODE_COOL: "cool",
HVAC_MODE_DRY: "dry",
HVAC_MODE_HEAT: "heat",
HVAC_MODE_FAN_ONLY: "wind",
HVACMode.HEAT_COOL: "auto",
HVACMode.COOL: "cool",
HVACMode.DRY: "dry",
HVACMode.HEAT: "heat",
HVACMode.FAN_ONLY: "wind",
}


Expand Down Expand Up @@ -162,11 +148,11 @@ def __init__(self, device):
self._hvac_modes = None

def _determine_features(self):
flags = SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_TEMPERATURE_RANGE
flags = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
if self._device.get_capability(
Capability.thermostat_fan_mode, Capability.thermostat
):
flags |= SUPPORT_FAN_MODE
flags |= ClimateEntityFeature.FAN_MODE
return flags

async def async_set_fan_mode(self, fan_mode):
Expand Down Expand Up @@ -197,9 +183,9 @@ async def async_set_temperature(self, **kwargs):
# Heat/cool setpoint
heating_setpoint = None
cooling_setpoint = None
if self.hvac_mode == HVAC_MODE_HEAT:
if self.hvac_mode == HVACMode.HEAT:
heating_setpoint = kwargs.get(ATTR_TEMPERATURE)
elif self.hvac_mode == HVAC_MODE_COOL:
elif self.hvac_mode == HVACMode.COOL:
cooling_setpoint = kwargs.get(ATTR_TEMPERATURE)
else:
heating_setpoint = kwargs.get(ATTR_TARGET_TEMP_LOW)
Expand Down Expand Up @@ -302,23 +288,23 @@ def supported_features(self):
@property
def target_temperature(self):
"""Return the temperature we try to reach."""
if self.hvac_mode == HVAC_MODE_COOL:
if self.hvac_mode == HVACMode.COOL:
return self._device.status.cooling_setpoint
if self.hvac_mode == HVAC_MODE_HEAT:
if self.hvac_mode == HVACMode.HEAT:
return self._device.status.heating_setpoint
return None

@property
def target_temperature_high(self):
"""Return the highbound target temperature we try to reach."""
if self.hvac_mode == HVAC_MODE_HEAT_COOL:
if self.hvac_mode == HVACMode.HEAT_COOL:
return self._device.status.cooling_setpoint
return None

@property
def target_temperature_low(self):
"""Return the lowbound target temperature we try to reach."""
if self.hvac_mode == HVAC_MODE_HEAT_COOL:
if self.hvac_mode == HVACMode.HEAT_COOL:
return self._device.status.heating_setpoint
return None

Expand Down Expand Up @@ -379,7 +365,7 @@ async def async_set_swing_mode(self, swing_mode):

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target operation mode."""
if hvac_mode == HVAC_MODE_OFF:
if hvac_mode == HVACMode.OFF:
await self.async_turn_off()
return
tasks = []
Expand All @@ -401,7 +387,7 @@ async def async_set_temperature(self, **kwargs):
tasks = []
# operation mode
if operation_mode := kwargs.get(ATTR_HVAC_MODE):
if operation_mode == HVAC_MODE_OFF:
if operation_mode == HVACMode.OFF:
tasks.append(self._device.switch_off(set_status=True))
else:
if not self._device.status.switch:
Expand Down Expand Up @@ -432,7 +418,7 @@ async def async_turn_off(self):

async def async_update(self):
"""Update the calculated fields of the AC."""
modes = {HVAC_MODE_OFF}
modes = {HVACMode.OFF}
for mode in self._device.status.supported_ac_modes:
if (state := AC_MODE_TO_STATE.get(mode)) is not None:
modes.add(state)
Expand Down Expand Up @@ -542,7 +528,7 @@ def preset_modes(self):
def hvac_mode(self):
"""Return current operation ie. heat, cool, idle."""
if not self._device.status.switch:
return HVAC_MODE_OFF
return HVACMode.OFF
return AC_MODE_TO_STATE.get(self._device.status.air_conditioner_mode)

@property
Expand All @@ -559,15 +545,15 @@ def supported_features(self):
]
if len(supported_ac_optional_modes) == 1 and supported_ac_optional_modes[0] == "off":
return (
SUPPORT_TARGET_TEMPERATURE
| SUPPORT_FAN_MODE
| SUPPORT_SWING_MODE
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.SWING_MODE
)
return (
SUPPORT_TARGET_TEMPERATURE
| SUPPORT_FAN_MODE
| SUPPORT_SWING_MODE
| SUPPORT_PRESET_MODE
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.SWING_MODE
| ClimateEntityFeature.PRESET_MODE
)

@property
Expand Down
15 changes: 7 additions & 8 deletions custom_components/smartthings/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import re

from homeassistant.const import (
ELECTRIC_POTENTIAL_VOLT,
UnitOfElectricPotential,
PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UnitOfPower,
UnitOfTemperature,
)

DOMAIN = "smartthings"
Expand Down Expand Up @@ -60,13 +59,13 @@
]

UNIT_MAP = {
"C": TEMP_CELSIUS,
"F": TEMP_FAHRENHEIT,
"C": UnitOfTemperature.CELSIUS,
"F": UnitOfTemperature.FAHRENHEIT,
"Hour": "Hour",
"minute": "Minute",
"%": PERCENTAGE,
"W": POWER_WATT,
"V": ELECTRIC_POTENTIAL_VOLT,
"W": UnitOfPower.WATT,
"V": UnitOfElectricPotential.VOLT,
}

TOKEN_REFRESH_INTERVAL = timedelta(days=14)
Expand Down
Loading