Move Insteon configuration panel to config entry (#105581)

* Move Insteon panel to the config menu

* Bump pyinsteon to 1.5.3

* Undo devcontainer.json changes

* Bump Insteon frontend

* Update config_flow.py

* Code cleanup

* Code review changes

* Fix failing tests

* Fix format

* Remove unnecessary exception

* codecov

* Remove return from try

* Fix merge mistake

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Tom Harris 2024-04-16 03:10:32 -04:00 committed by GitHub
parent 1dfabf34c4
commit c5c407b3bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 988 additions and 766 deletions

View file

@ -3,12 +3,14 @@
from typing import Any
from pyinsteon import devices
from pyinsteon.address import Address
from pyinsteon.constants import DeviceAction
import voluptuous as vol
from homeassistant.components import websocket_api
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.dispatcher import async_dispatcher_send
from ..const import (
DEVICE_ADDRESS,
@ -18,8 +20,17 @@ from ..const import (
ID,
INSTEON_DEVICE_NOT_FOUND,
MULTIPLE,
SIGNAL_REMOVE_HA_DEVICE,
SIGNAL_REMOVE_INSTEON_DEVICE,
SIGNAL_REMOVE_X10_DEVICE,
TYPE,
)
from ..schemas import build_x10_schema
from .config import add_x10_device, remove_device_override, remove_x10_device
X10_DEVICE = "x10_device"
X10_DEVICE_SCHEMA = build_x10_schema()
REMOVE_ALL_REFS = "remove_all_refs"
def compute_device_name(ha_device):
@ -139,3 +150,61 @@ async def websocket_cancel_add_device(
"""Cancel the Insteon all-linking process."""
await devices.async_cancel_all_linking()
connection.send_result(msg[ID])
@websocket_api.websocket_command(
{
vol.Required(TYPE): "insteon/device/remove",
vol.Required(DEVICE_ADDRESS): str,
vol.Required(REMOVE_ALL_REFS): bool,
}
)
@websocket_api.require_admin
@websocket_api.async_response
async def websocket_remove_device(
hass: HomeAssistant,
connection: websocket_api.connection.ActiveConnection,
msg: dict[str, Any],
) -> None:
"""Remove an Insteon device."""
address = msg[DEVICE_ADDRESS]
remove_all_refs = msg[REMOVE_ALL_REFS]
if address.startswith("X10"):
_, housecode, unitcode = address.split(".")
unitcode = int(unitcode)
async_dispatcher_send(hass, SIGNAL_REMOVE_X10_DEVICE, housecode, unitcode)
remove_x10_device(hass, housecode, unitcode)
else:
address = Address(address)
remove_device_override(hass, address)
async_dispatcher_send(hass, SIGNAL_REMOVE_HA_DEVICE, address)
async_dispatcher_send(
hass, SIGNAL_REMOVE_INSTEON_DEVICE, address, remove_all_refs
)
connection.send_result(msg[ID])
@websocket_api.websocket_command(
{
vol.Required(TYPE): "insteon/device/add_x10",
vol.Required(X10_DEVICE): X10_DEVICE_SCHEMA,
}
)
@websocket_api.require_admin
@websocket_api.async_response
async def websocket_add_x10_device(
hass: HomeAssistant,
connection: websocket_api.connection.ActiveConnection,
msg: dict[str, Any],
) -> None:
"""Get the schema for the X10 devices configuration."""
x10_device = msg[X10_DEVICE]
try:
add_x10_device(hass, x10_device)
except ValueError:
connection.send_error(msg[ID], code="duplicate", message="Duplicate X10 device")
return
connection.send_result(msg[ID])