generated from ludeeus/integration_blueprint
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bump ta-cmi to 3.0.0 * Add CAN-IDs to config flow * Add CAN-IDs to options flow * Add config flow tests * Update sensor handling * Add repair flow * Update README
- Loading branch information
1 parent
5a70512
commit 74f6514
Showing
18 changed files
with
395 additions
and
124 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
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
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 @@ | ||
"""Issues for Technische Alternative CoE integration.""" | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import issue_registry as ir | ||
|
||
from custom_components.ta_coe import CONF_CAN_IDS | ||
|
||
from .const import DOMAIN | ||
|
||
|
||
def check_coe_server_2x_issue(hass: HomeAssistant, entry: ConfigEntry) -> None: | ||
"""Check and create issues related to the CoE server 2.x upgrade.""" | ||
|
||
if entry.data.get(CONF_CAN_IDS, None) is None: | ||
ir.async_create_issue( | ||
hass, | ||
DOMAIN, | ||
"add_missing_can_id", | ||
data=entry.entry_id, | ||
is_fixable=True, | ||
severity=ir.IssueSeverity.ERROR, | ||
translation_key="add_missing_can_id", | ||
) |
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,60 @@ | ||
"""Repairs for Technische Alternative CoE integration.""" | ||
from typing import Any | ||
|
||
import homeassistant.helpers.config_validation as cv | ||
import voluptuous as vol | ||
from homeassistant import config_entries, data_entry_flow | ||
from homeassistant.components.repairs import RepairsFlow | ||
from homeassistant.core import HomeAssistant | ||
|
||
from custom_components.ta_coe import CONF_CAN_IDS | ||
from custom_components.ta_coe.config_flow import CANIDError, split_can_ids | ||
|
||
|
||
class MissingCANIDRepairFlow(RepairsFlow): | ||
"""Handler for an missing CAN-ID fixing flow.""" | ||
|
||
def __init__(self, config_entry: config_entries.ConfigEntry): | ||
"""Initialize.""" | ||
self.config_entry = config_entry | ||
self.config_data = dict(self.config_entry.data) | ||
|
||
async def async_step_init( | ||
self, user_input: dict[str, str] | None = None | ||
) -> data_entry_flow.FlowResult: | ||
"""Handle the first step of a fix flow.""" | ||
return await self.async_step_form() | ||
|
||
async def async_step_form( | ||
self, user_input: dict[str, Any] | None = None | ||
) -> data_entry_flow.FlowResult: | ||
"""Handle the first step of a fix flow.""" | ||
|
||
errors: dict[str, Any] = {} | ||
|
||
if user_input is not None: | ||
try: | ||
self.config_data[CONF_CAN_IDS] = split_can_ids(user_input[CONF_CAN_IDS]) | ||
except CANIDError: | ||
errors["base"] = "invalid_can_id" | ||
else: | ||
self.hass.config_entries.async_update_entry( | ||
self.config_entry, data=self.config_data | ||
) | ||
return self.async_create_entry(title="", data={}) | ||
|
||
return self.async_show_form( | ||
step_id="form", | ||
data_schema=vol.Schema({vol.Required(CONF_CAN_IDS): cv.string}), | ||
errors=errors, | ||
) | ||
|
||
|
||
async def async_create_fix_flow( | ||
hass: HomeAssistant, | ||
issue_id: str, | ||
data: Any | None, | ||
) -> RepairsFlow: | ||
"""Entry point for repair flows.""" | ||
if issue_id == "add_missing_can_id": | ||
return MissingCANIDRepairFlow(hass.config_entries.async_get_entry(data)) |
Oops, something went wrong.