Skip to content

Commit

Permalink
Merge pull request #9 from quielb/speed_control
Browse files Browse the repository at this point in the history
Revert removal of custom services
  • Loading branch information
quielb authored May 24, 2021
2 parents 1628ae3 + 5363f3f commit 81f93a3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 10 deletions.
1 change: 0 additions & 1 deletion .github/workflows/hacs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: HACS Action

on:
push:
pull_request:

jobs:
Expand Down
47 changes: 43 additions & 4 deletions custom_components/airscape/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
# Add devices
add_entities([AirscapeWHF(device, name, minimum)], True)

def service_speed_up(call):
"""Handle speed_up service call."""
entity_id = call.data.get("entity_id")
_LOGGER.debug("Calling speed_up for %s", entity_id)

entity = hass.data[DOMAIN].get_entity(entity_id)
entity.speed_up()

def service_slow_down(call):
"""Handle slow_down service call."""
entity_id = call.data.get("entity_id")
_LOGGER.debug("Calling slow_down for %s", entity_id)

entity = hass.data[DOMAIN].get_entity(entity_id)
entity.slow_down()

def service_add_time(call):
"""Handle slow_down service call."""
entity_id = call.data.get("entity_id")
Expand All @@ -64,6 +80,8 @@ def service_add_time(call):
entity = hass.data[DOMAIN].get_entity(entity_id)
entity.add_time()

hass.services.register(AIRSCAPE_DOMAIN, "speed_up", service_speed_up)
hass.services.register(AIRSCAPE_DOMAIN, "slow_down", service_slow_down)
hass.services.register(AIRSCAPE_DOMAIN, "add_time", service_add_time)

return True
Expand Down Expand Up @@ -122,7 +140,9 @@ def turn_on(
try:
if percentage is not None:
self._fan.speed = math.ceil(
percentage_to_ranged_value((1, self._fan.max_speed), percentage)
percentage_to_ranged_value(
(self._minimum_speed, self._fan.max_speed), percentage
)
)
else:
self._fan.speed = self._minimum_speed
Expand All @@ -146,24 +166,43 @@ def add_time(self):
@property
def speed_count(self):
"""Return the number of speeds the fan supports."""
return int_states_in_range((1, self._fan.max_speed))
return int_states_in_range((self._minimum_speed, self._fan.max_speed))

@property
def percentage(self):
"""Return the current speed percentage"""
return ranged_value_to_percentage((1, self._fan.max_speed), self._speed)
return ranged_value_to_percentage(
(self._minimum_speed, self._fan.max_speed), self._speed
)

def set_percentage(self, percentage: int):
"""Set the speed of the fan."""
if not bool(percentage):
self._fan.is_on = False
try:
self._fan.speed = math.ceil(
percentage_to_ranged_value((1, self._fan.max_speed), percentage)
percentage_to_ranged_value(
(self._minimum_speed, self._fan.max_speed), percentage
)
)
except (airscape.exceptions.ConnectionError, airscape.exceptions.Timeout):
self._available = False

def speed_up(self):
"""Instruct fan to increment speed up by 1."""
try:
self._fan.speed_up()
except (airscape.exceptions.ConnectionError, airscape.exceptions.Timeout):
self._available = False

def slow_down(self):
"""Instruct fan to increment speed down by 1."""
try:
if self._speed > self._minimum_speed:
self._fan.slow_down()
except (airscape.exceptions.ConnectionError, airscape.exceptions.Timeout):
self._available = False

def update(self):
"""Fetch new state data for this fan.
Expand Down
2 changes: 1 addition & 1 deletion custom_components/airscape/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Airscape Whole House Fan",
"documentation": "https://www.home-assistant.io/components/fan.airscape",
"issue_tracker": "https://github.com/quielb/hass-airscape/issues",
"version": "0.1.9.2",
"version": "0.1.9.3",
"requirements": [
"airscape==0.1.9.2"
],
Expand Down
16 changes: 16 additions & 0 deletions custom_components/airscape/services.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
speed_up:
name: Speed Up
description: Bump the WHF speed up by 1.
fields:
entity_id:
name: Entity ID
description: Entity ID of the fan to change.
required: true
slow_down:
name: Slow Down
description: Bump the WHF speed down by 1.
fields:
entity_id:
name: Entity ID
description: Entity ID of the fan to change.
required: true
add_time:
name: Add Time
description: Add an hour to the automatic shutoff timer of the WHF.
Expand Down
13 changes: 9 additions & 4 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ A Home Assistant custom component to control Airscape Whole House Fans with Gen2

### Changes

{% if version_installed.replace("v", "").replace(".","") | int < 190 %}
{% if version_installed.replace("v", "").replace(".","") | int < 193 %}

- Reverted the removal of custom services slow_down and speed_up. The built in service fan.decrease_speed allows the fan to be turned off
if decreased_speed is at the minimum speed.
{% endif %}
{% if version_installed.replace("v", "").replace(".","") | int < 190 %}

- Added the ability to dynamically determine max speed based on model. Should allow for speed to be correctly represented in the Front End.
- Updated Entity to utilized the new percentage speed model in HA.
Expand Down Expand Up @@ -43,10 +48,10 @@ fan:
The minimum attribute is optional. It specifies the minimum starting speed and prevents the speed from going below that value.
This component adds one custom service:
This component adds three custom service:
```
airscape.speed_up
airscape.slow_down
airscape.add_time
```

This allows for adding an hour of time to the timer on the fan.

0 comments on commit 81f93a3

Please sign in to comment.