Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #78 Add new option toggle_list #94

Merged
merged 2 commits into from
Oct 13, 2022
Merged
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
36 changes: 28 additions & 8 deletions custom_components/tasmota_irhvac/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
CONF_KEEP_MODE,
CONF_SWINGV,
CONF_SWINGH,
CONF_TOGGLE_LIST,
DATA_KEY,
DOMAIN,
DEFAULT_NAME,
Expand Down Expand Up @@ -170,6 +171,7 @@
SERVICE_SLEEP_MODE,
SERVICE_SET_SWINGV,
SERVICE_SET_SWINGH,
TOGGLE_ALL_LIST,
)

DEFAULT_MODES_LIST = [
Expand Down Expand Up @@ -265,6 +267,10 @@
vol.Optional(CONF_KEEP_MODE, default=DEFAULT_CONF_KEEP_MODE): cv.boolean,
vol.Optional(CONF_SWINGV): cv.string,
vol.Optional(CONF_SWINGH): cv.string,
vol.Optional(CONF_TOGGLE_LIST, default=[]): vol.All(
cv.ensure_list,
[vol.In(TOGGLE_ALL_LIST)],
),
}
)

Expand Down Expand Up @@ -465,7 +471,7 @@ def __init__(
self._model = config[CONF_MODEL]
self._celsius = config[CONF_CELSIUS]
self._light = config[CONF_LIGHT].lower()
self._filters = config[CONF_FILTER].lower()
self._filter = config[CONF_FILTER].lower()
self._clean = config[CONF_CLEAN].lower()
self._beep = config[CONF_BEEP].lower()
self._sleep = config[CONF_SLEEP].lower()
Expand All @@ -476,6 +482,7 @@ def __init__(
self._swingh = config.get(CONF_SWINGH).lower() if config.get(CONF_SWINGH) is not None else None
self._fix_swingv = None
self._fix_swingh = None
self._toggle_list = config[CONF_TOGGLE_LIST]

availability_topic = config.get(CONF_AVAILABILITY_TOPIC)
if (availability_topic) is None:
Expand Down Expand Up @@ -513,10 +520,10 @@ async def async_added_to_hass(self):
if old_state.attributes.get(ATTR_LAST_ON_MODE) is not None:
self._last_on_mode = old_state.attributes.get(ATTR_LAST_ON_MODE)

for attr in ATTRIBUTES_IRHVAC:
for attr, prop in ATTRIBUTES_IRHVAC.items():
val = old_state.attributes.get(attr)
if val is not None:
setattr(self, "_" + attr, val)
setattr(self, "_" + prop, val)
if old_state.state:
self._hvac_mode = old_state.state
self._enabled = self._hvac_mode != HVAC_MODE_OFF
Expand All @@ -541,6 +548,9 @@ async def async_added_to_hass(self):
self.power_mode = STATE_ON
self._enabled = True

for key in self._toggle_list:
setattr(self, '_' + key.lower(), 'off')

if self._temp_sensor:
async_track_state_change(self.hass, self._temp_sensor, self._async_sensor_changed)

Expand Down Expand Up @@ -603,7 +613,7 @@ async def state_message_received(msg):
if "Light" in payload:
self._light = payload["Light"].lower()
if "Filter" in payload:
self._filters = payload["Filter"].lower()
self._filter = payload["Filter"].lower()
if "Clean" in payload:
self._clean = payload["Clean"].lower()
if "Beep" in payload:
Expand Down Expand Up @@ -674,6 +684,10 @@ async def state_message_received(msg):
else:
self._enabled = True

# Set toggles to 'off'
for key in self._toggle_list:
setattr(self, '_' + key.lower(), 'off')

# Update HA UI and State
await self.async_update_ha_state()
#self.async_schedule_update_ha_state()
Expand Down Expand Up @@ -720,8 +734,8 @@ async def async_will_remove_from_hass(self):
@property
def extra_state_attributes(self):
"""Return the state attributes of the device."""
return {attribute: getattr(self, '_' + attribute)
for attribute in ATTRIBUTES_IRHVAC}
return {attr: getattr(self, '_' + prop)
for attr, prop in ATTRIBUTES_IRHVAC.items()}

@property
def should_poll(self):
Expand Down Expand Up @@ -956,7 +970,7 @@ async def async_set_filters(self, filters):
"""Set new target filters mode."""
if filters not in ON_OFF_LIST:
return
self._filters = filters.lower()
self._filter = filters.lower()
await self.async_send_cmd()

async def async_set_clean(self, clean):
Expand Down Expand Up @@ -1173,13 +1187,19 @@ async def send_ir(self):
"Turbo": self._turbo,
"Econo": self._econo,
"Light": self._light,
"Filter": self._filters,
"Filter": self._filter,
"Clean": self._clean,
"Beep": self._beep,
"Sleep": self._sleep,
"Clock": int(_min),
"Weekday": int(_dt.weekday()),
}
for key in self._toggle_list:
setattr(self, '_' + key.lower(), 'off')

payload = (json.dumps(payload_data))
# Publish mqtt message
await mqtt.async_publish(self.hass, self.topic, payload)

# Update HA UI and State
self.async_schedule_update_ha_state()
16 changes: 15 additions & 1 deletion custom_components/tasmota_irhvac/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
CONF_KEEP_MODE = "keep_mode_when_off"
CONF_SWINGV = "default_swingv"
CONF_SWINGH = "default_swingh"
CONF_TOGGLE_LIST = "toggle_list"

# Platform specific default values
DEFAULT_NAME = "IR AirConditioner"
Expand Down Expand Up @@ -150,7 +151,7 @@
ATTR_TURBO: 'turbo',
ATTR_QUIET: 'quiet',
ATTR_LIGHT: 'light',
ATTR_FILTERS: 'filters',
ATTR_FILTERS: 'filter',
ATTR_CLEAN: 'clean',
ATTR_BEEP: 'beep',
ATTR_SLEEP: 'sleep',
Expand All @@ -169,3 +170,16 @@
'on',
'off'
]

TOGGLE_ALL_LIST = [
'SwingV',
'SwingH',
'Quiet',
'Turbo',
'Econo',
'Light',
'Filter',
'Clean',
'Beep',
'Sleep',
]
13 changes: 13 additions & 0 deletions examples/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,16 @@ climate:
default_swingv: "high" #optional - default "" string value
default_swingh: "left" #optional - default "" string value
keep_mode_when_off: True #optional - default False boolean value : Must be True for MITSUBISHI_AC, ECOCLIM, etc.
toggle_list: #optional - default []
# The toggled property is a setting that does not retain the On state.
# Set this if your AC properties are toggle function.
#- Beep
#- Clean
#- Econo
#- Filter
#- Light
#- Quiet
#- Sleep
#- SwingH
#- SwingV
#- Turbo