generated from ludeeus/integration_blueprint
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.1.0 - automatic reconnect, request assignment
- Loading branch information
Showing
9 changed files
with
164 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,4 +103,5 @@ venv.bak/ | |
# mypy | ||
.mypy_cache/ | ||
|
||
venv/ | ||
venv/ | ||
hass_debug_env/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python: hass", | ||
"type": "python", | ||
"request": "launch", | ||
"justMyCode": false, | ||
"module": "homeassistant", | ||
"args": ["-c", "./hass_debug_env"] | ||
}, | ||
{ | ||
"name": "Python: Current File", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${file}", | ||
"console": "integratedTerminal" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.pythonPath": "venv/bin/python" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""FoldingAtHomeControl services.""" | ||
import voluptuous as vol | ||
|
||
from homeassistant.helpers import config_validation as cv | ||
|
||
from .const import ( | ||
CONF_ADDRESS, | ||
_LOGGER, | ||
DOMAIN, | ||
) | ||
|
||
DOMAIN_SERVICES = f"{DOMAIN}_services" | ||
|
||
SERVICE_ADDRESS = "address" | ||
|
||
SERVICE_REQUEST_WORK_SERVER_ASSIGNMENT = "request_work_server_assignment" | ||
SERVICE_REQUEST_WORK_SERVER_ASSIGNMENT_SCHEMA = vol.Schema( | ||
{vol.Required(SERVICE_ADDRESS): cv.string} | ||
) | ||
|
||
|
||
async def async_setup_services(hass): | ||
"""Set up services for FoldingAtHomeControl integration.""" | ||
if hass.data.get(DOMAIN_SERVICES, False): | ||
return | ||
|
||
hass.data[DOMAIN_SERVICES] = True | ||
|
||
async def async_call_folding_at_home_control_service(service_call): | ||
"""Call correct FoldingAtHomeControl service.""" | ||
service = service_call.service | ||
service_data = service_call.data | ||
|
||
if service == SERVICE_REQUEST_WORK_SERVER_ASSIGNMENT: | ||
await async_request_assignment_service(hass, service_data) | ||
|
||
hass.services.async_register( | ||
DOMAIN, | ||
SERVICE_REQUEST_WORK_SERVER_ASSIGNMENT, | ||
async_call_folding_at_home_control_service, | ||
schema=SERVICE_REQUEST_WORK_SERVER_ASSIGNMENT_SCHEMA, | ||
) | ||
|
||
|
||
async def async_unload_services(hass): | ||
"""Unload deCONZ services.""" | ||
if not hass.data.get(DOMAIN_SERVICES): | ||
return | ||
|
||
hass.data[DOMAIN_SERVICES] = False | ||
|
||
hass.services.async_remove(DOMAIN, SERVICE_REQUEST_WORK_SERVER_ASSIGNMENT) | ||
|
||
|
||
async def async_request_assignment_service(hass, data): | ||
"""Let the client request a new work server assignment.""" | ||
|
||
address = data[SERVICE_ADDRESS] | ||
|
||
for config_entry in hass.data[DOMAIN]: | ||
if hass.data[DOMAIN][config_entry].config_entry.data[CONF_ADDRESS] == address: | ||
await hass.data[DOMAIN][ | ||
config_entry | ||
].client.request_work_server_assignment() | ||
return | ||
_LOGGER.warning("Could not find a registered integration with address: %s", address) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
request_work_server_assignment: | ||
description: Request a new assignment from the work server. | ||
fields: | ||
address: | ||
description: The IP address or hostname of the client. It can be found as part of the integration name. | ||
example: 'localhost' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
PyFoldingAtHomeControl==0.1.6 | ||
PyFoldingAtHomeControl==1.0.0 |