Skip to content

Commit 88ef6cd

Browse files
author
Ted Roberts
committed
Return send_raw_command response payloads
1 parent b6fc8dc commit 88ef6cd

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

custom_components/novastar_h/__init__.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import voluptuous as vol
77
from homeassistant.config_entries import ConfigEntry
88
from homeassistant.const import CONF_HOST, CONF_PORT
9-
from homeassistant.core import HomeAssistant, ServiceCall
9+
from homeassistant.core import HomeAssistant, ServiceCall, SupportsResponse
1010
import homeassistant.helpers.config_validation as cv
1111

1212
from .api import NovastarClient
@@ -146,7 +146,7 @@ def resolve_coordinator_by_host(
146146
if hass.services.has_service(DOMAIN, SERVICE_SEND_RAW_COMMAND):
147147
hass.services.async_remove(DOMAIN, SERVICE_SEND_RAW_COMMAND)
148148

149-
async def async_send_raw_command(call: ServiceCall) -> None:
149+
async def async_send_raw_command(call: ServiceCall) -> dict[str, Any]:
150150
"""Handle send_raw_command service call."""
151151
host = call.data.get(CONF_HOST)
152152
if isinstance(host, str):
@@ -164,7 +164,7 @@ async def async_send_raw_command(call: ServiceCall) -> None:
164164

165165
if coordinator_found is None:
166166
_LOGGER.error(error_message)
167-
return
167+
return {"ok": False, "error": error_message}
168168

169169
client_found = None
170170
raw_enabled = False
@@ -190,14 +190,17 @@ async def async_send_raw_command(call: ServiceCall) -> None:
190190
_LOGGER.error(
191191
"No Novastar device found at %s", resolved_host
192192
)
193-
return
193+
return {"ok": False, "error": f"No Novastar device found at {resolved_host}"}
194194

195195
if not raw_enabled:
196196
_LOGGER.error(
197197
"Raw commands are not enabled for Novastar device at %s",
198198
resolved_host,
199199
)
200-
return
200+
return {
201+
"ok": False,
202+
"error": f"Raw commands are not enabled for Novastar device at {resolved_host}",
203+
}
201204

202205
# TEMPORARY DEBUG LOGGING - can be removed in future releases
203206
_LOGGER.warning(
@@ -209,14 +212,29 @@ async def async_send_raw_command(call: ServiceCall) -> None:
209212
result = await client_found.async_send_raw_command(endpoint, effective_body)
210213
if result is None:
211214
_LOGGER.warning("Raw command to %s failed", endpoint)
215+
return {
216+
"ok": False,
217+
"host": resolved_host,
218+
"endpoint": endpoint,
219+
"request_body": effective_body,
220+
"response": None,
221+
}
212222
else:
213223
_LOGGER.debug("Raw command result: %s", result)
224+
return {
225+
"ok": True,
226+
"host": resolved_host,
227+
"endpoint": endpoint,
228+
"request_body": effective_body,
229+
"response": result,
230+
}
214231

215232
hass.services.async_register(
216233
DOMAIN,
217234
SERVICE_SEND_RAW_COMMAND,
218235
async_send_raw_command,
219236
schema=SERVICE_SEND_RAW_COMMAND_SCHEMA,
237+
supports_response=SupportsResponse.OPTIONAL,
220238
)
221239

222240
if not hass.services.has_service(DOMAIN, SERVICE_SET_LAYER_SOURCE):

custom_components/novastar_h/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
}
2222
],
2323
"zeroconf": ["_novastar._tcp.local."],
24-
"version": "0.2.65"
24+
"version": "0.2.66"
2525
}

0 commit comments

Comments
 (0)