diff --git a/custom_components/yerushamayim/__init__.py b/custom_components/yerushamayim/__init__.py index e69de29..691ebf0 100644 --- a/custom_components/yerushamayim/__init__.py +++ b/custom_components/yerushamayim/__init__.py @@ -0,0 +1,26 @@ +"""The Yerushamayim integration.""" +from __future__ import annotations + +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import Platform +from homeassistant.core import HomeAssistant + +from .const import DOMAIN + +PLATFORMS: list[Platform] = [Platform.WEATHER, Platform.SENSOR] + +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: + """Set up Yerushamayim from a config entry.""" + hass.data.setdefault(DOMAIN, {}) + hass.data[DOMAIN][entry.entry_id] = entry.data + + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + + return True + +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: + """Unload a config entry.""" + if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): + hass.data[DOMAIN].pop(entry.entry_id) + + return unload_ok \ No newline at end of file diff --git a/custom_components/yerushamayim/config_flow.py b/custom_components/yerushamayim/config_flow.py index 8190e79..76782a1 100644 --- a/custom_components/yerushamayim/config_flow.py +++ b/custom_components/yerushamayim/config_flow.py @@ -3,34 +3,15 @@ from typing import Any -import voluptuous as vol - from homeassistant import config_entries from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResult -from homeassistant.exceptions import HomeAssistantError from .const import DOMAIN -STEP_USER_DATA_SCHEMA = vol.Schema({}) - async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]: """Validate the user input allows us to connect.""" - # TODO: Validate the data can be used to set up a connection. - - # If your PyPI package is not built with async, pass your methods - # to the executor: - # await hass.async_add_executor_job( - # your_validate_func, data["username"], data["password"] - # ) - - # If you cannot connect: - # throw CannotConnect - - # If the authentication is wrong: - # throw InvalidAuth - - # Return info that you want to store in the config entry. + # TODO: Add any validation logic here if needed in the future return {"title": "Yerushamayim Weather"} class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): @@ -44,29 +25,14 @@ async def async_step_user( """Handle the initial step.""" if user_input is None: return self.async_show_form( - step_id="user", data_schema=STEP_USER_DATA_SCHEMA + step_id="user", + data_schema=None, + description_placeholders={ + "name": "Yerushamayim" + }, ) - errors = {} - - try: - info = await validate_input(self.hass, user_input) - except CannotConnect: - errors["base"] = "cannot_connect" - except InvalidAuth: - errors["base"] = "invalid_auth" - except Exception: # pylint: disable=broad-except - _LOGGER.exception("Unexpected exception") - errors["base"] = "unknown" - else: - return self.async_create_entry(title=info["title"], data=user_input) - - return self.async_show_form( - step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors - ) - -class CannotConnect(HomeAssistantError): - """Error to indicate we cannot connect.""" + await self.async_set_unique_id(DOMAIN) + self._abort_if_unique_id_configured() -class InvalidAuth(HomeAssistantError): - """Error to indicate there is invalid auth.""" \ No newline at end of file + return self.async_create_entry(title="Yerushamayim Weather", data={}) \ No newline at end of file diff --git a/custom_components/yerushamayim/manifest.json b/custom_components/yerushamayim/manifest.json index 0e17a8a..3ad426a 100644 --- a/custom_components/yerushamayim/manifest.json +++ b/custom_components/yerushamayim/manifest.json @@ -2,6 +2,7 @@ "domain": "yerushamayim", "name": "Yerushamayim Weather", "config_flow": true, + "integration_type": "hub", "documentation": "https://github.com/chilikla/yerushamayim", "issue_tracker": "https://github.com/chilikla/yerushamayim/issues", "requirements": ["beautifulsoup4==4.10.0"], @@ -12,5 +13,5 @@ "after_dependencies": ["rest"], "codeowners": ["chilikla"], "iot_class": "cloud_polling", - "version": "0.0.14" + "version": "0.0.0" } \ No newline at end of file diff --git a/custom_components/yerushamayim/strings.json b/custom_components/yerushamayim/strings.json new file mode 100644 index 0000000..c20148f --- /dev/null +++ b/custom_components/yerushamayim/strings.json @@ -0,0 +1,14 @@ +{ + "title": "Yerushamayim Weather", + "config": { + "step": { + "user": { + "title": "[%key:component::yerushamayim::title%]", + "description": "Do you want to add Yerushamayim to Home Assistant?" + } + }, + "abort": { + "already_configured": "[%key:common::config_flow::abort::already_configured_service%]" + } + } + } \ No newline at end of file