Skip to content

Commit

Permalink
New event code and Forcing single instance only
Browse files Browse the repository at this point in the history
  • Loading branch information
jampez77 committed Oct 16, 2024
1 parent ec9131e commit 9e79ca9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is by no means an extensive list of event codes that a parcel can encounter
- EVOAC: Item received at
- EVAIE/EVAIP: Sender preparing/despatching item
- EVPPA: Accepted at Parcelshop
- EVDAV/EVIMC/EVDAC/EVBAV: Item Received
- EVDAV/EVIMC/EVDAC/EVBAV/EVIAV: Item Received
- EVKOP: Delivered by
- EVNRT: Item Retention
- EVOCO: We've received your item and its now being processed for delivery.
Expand Down
23 changes: 16 additions & 7 deletions custom_components/royalmail/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntryState
from homeassistant.config_entries import ConfigEntryState, ConfigFlowResult
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.aiohttp_client import async_get_clientsession

Expand Down Expand Up @@ -61,10 +60,18 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

VERSION = 1

@callback
def _entry_exists(self):
"""Check if an entry for this domain already exists."""
existing_entries = self._async_current_entries()
return len(existing_entries) > 0

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
) -> ConfigFlowResult:
"""Handle the initial step."""
if self._entry_exists():
return self.async_abort(reason="already_configured")

errors: dict[str, str] = {}
if user_input is not None:
Expand Down Expand Up @@ -111,7 +118,7 @@ async def async_step_user(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
)

async def async_step_import(self, import_data=None) -> FlowResult:
async def async_step_import(self, import_data=None) -> ConfigFlowResult:
"""Handle the import step for the service call."""

if import_data is not None:
Expand Down Expand Up @@ -168,7 +175,9 @@ async def async_step_import(self, import_data=None) -> FlowResult:
# Explicitly handle the case where import_data is None
return self.async_abort(reason="no_import_data")

async def async_step_reauth(self, user_input: Mapping[str, Any]) -> FlowResult:
async def async_step_reauth(
self, user_input: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle reauth step."""

session = async_get_clientsession(self.hass)
Expand Down Expand Up @@ -197,7 +206,7 @@ async def async_step_reauth(self, user_input: Mapping[str, Any]) -> FlowResult:

async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
) -> ConfigFlowResult:
"""Handle the re-auth step."""
if user_input is not None:
# Here you would handle any form submission from the user
Expand All @@ -219,7 +228,7 @@ def __init__(self, config_entry) -> None:
"""Init."""
self.config_entry = config_entry

async def async_step_init(self, user_input=None) -> FlowResult:
async def async_step_init(self, user_input=None) -> ConfigFlowResult:
"""Init."""
return self.async_show_form(
step_id="init",
Expand Down
1 change: 1 addition & 0 deletions custom_components/royalmail/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"EVNDA",
"EVBAV",
"EVKLS",
"EVIAV",
]
PARCEL_DELIVERY_FAILED = ["EVKNR"]
PARCEL_DELIVERED = ["EVKSP", "EVKOP", "EVKSF"]
Expand Down
2 changes: 1 addition & 1 deletion custom_components/royalmail/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"issue_tracker": "https://github.com/jampez77/RoyalMail/issues",
"requirements": [],
"ssdp": [],
"version": "2024.10.5",
"version": "2024.10.6",
"zeroconf": []
}

0 comments on commit 9e79ca9

Please sign in to comment.