Skip to content

Commit

Permalink
Add reconnect service
Browse files Browse the repository at this point in the history
  • Loading branch information
pp81381 committed Jan 16, 2024
1 parent ce514e9 commit 3ad1968
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
16 changes: 14 additions & 2 deletions custom_components/nice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
EVENT_HOMEASSISTANT_STARTED,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry as dr
from nicett6.ciw_helper import CIWHelper
from nicett6.cover import Cover
Expand Down Expand Up @@ -50,6 +50,7 @@
CONF_SERIAL_PORT,
DOMAIN,
SERVICE_APPLY_PRESET,
SERVICE_RECONNECT,
)

PLATFORMS = ["cover", "sensor"]
Expand Down Expand Up @@ -95,6 +96,11 @@ async def handle_stop(event: Event) -> None:
async def add_cover(self, *args) -> TT6Cover:
return await self._controller.add_cover(*args)

async def reconnect(self):
# TODO: Move this into CoverManager
assert self._controller._conn is not None
await self._controller._conn.connect()

async def _stop(self):
await _await_cancel(self._message_tracker_task)
await self._controller.close()
Expand Down Expand Up @@ -260,7 +266,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

async def apply_preset(call) -> None:
async def apply_preset(call: ServiceCall) -> None:
"""Service call to apply a preset."""
for preset in entry.options[CONF_PRESETS].values():
if preset[CONF_NAME] == call.data.get(CONF_NAME):
Expand All @@ -284,6 +290,12 @@ async def apply_preset(call) -> None:
schema=SERVICE_APPLY_PRESET_SCHEMA,
)

async def reconnect(call: ServiceCall) -> None:
for c in nd.controllers.values():
await c.reconnect()

hass.services.async_register(DOMAIN, SERVICE_RECONNECT, reconnect)

return True


Expand Down
2 changes: 1 addition & 1 deletion custom_components/nice/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from homeassistant.helpers.entity_registry import async_entries_for_config_entry
from homeassistant.helpers.entity_registry import async_get as get_entity_registry
from homeassistant.util import slugify
from nicett6.connection import open_connection
from nicett6.tt6_connection import open_connection
from nicett6.utils import MAX_ASPECT_RATIO, MIN_ASPECT_RATIO
from serial import SerialException

Expand Down
5 changes: 3 additions & 2 deletions custom_components/nice/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
CHOICE_ASPECT_RATIO_OTHER = "aspect_ratio_other"

SERVICE_APPLY_PRESET = "apply_preset"
SERVICE_SET_DROP_PERCENT = "set_drop_percent"
SERVICE_SEND_SIMPLE_COMMAND = "send_simple_command"
SERVICE_RECONNECT = "reconnect"
SERVICE_REFRESH_POSITION = "refresh_position"
SERVICE_SEND_SIMPLE_COMMAND = "send_simple_command"
SERVICE_SET_DROP_PERCENT = "set_drop_percent"

ACTION_ADD_CIW = "Add CIW Helper"
ACTION_DEL_CIW = "Delete CIW Helper(s)"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/nice/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/pp81381/nice/issues",
"requirements": [
"nicett6-pp81381==0.30"
"nicett6-pp81381==0.31"
],
"version": "1.0.3"
"version": "1.2.7"
}
2 changes: 2 additions & 0 deletions custom_components/nice/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ apply_preset:
selector:
text:

reconnect:

set_drop_percent:
target:
entity:
Expand Down
4 changes: 4 additions & 0 deletions custom_components/nice/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
}
}
},
"reconnect": {
"name": "Reconnect",
"description": "Reconnect to the controller(s)"
},
"set_drop_percent": {
"name": "Set Cover Drop Percent",
"description": "Set the Cover to the specified drop in percent",
Expand Down
4 changes: 4 additions & 0 deletions custom_components/nice/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
}
}
},
"reconnect": {
"name": "Reconnect",
"description": "Reconnect to the controller(s)"
},
"set_drop_percent": {
"name": "Set Cover Drop Percent",
"description": "Set the Cover to the specified drop in percent",
Expand Down

0 comments on commit 3ad1968

Please sign in to comment.