Skip to content

Commit

Permalink
v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zubir2k authored Jan 24, 2025
1 parent 4d23db4 commit e17a09c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
8 changes: 8 additions & 0 deletions custom_components/dummy_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant

DOMAIN = "dummy_tracker"
PLATFORMS: list[Platform] = [Platform.DEVICE_TRACKER]

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Dummy Device Tracker from a config entry."""
# Register update listener
entry.async_on_unload(entry.add_update_listener(update_listener))

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True

async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update."""
await hass.config_entries.async_reload(entry.entry_id)

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
8 changes: 8 additions & 0 deletions custom_components/dummy_tracker/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
DOMAIN = "dummy_tracker"

class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Dummy Device Tracker."""

VERSION = 1

async def async_step_user(
Expand Down Expand Up @@ -51,3 +53,9 @@ async def async_step_user(
}
),
)

@staticmethod
def async_get_options_flow(config_entry):
"""Create the options flow."""
from .options_flow import OptionsFlowHandler
return OptionsFlowHandler(config_entry)
58 changes: 58 additions & 0 deletions custom_components/dummy_tracker/options_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Options flow for Dummy Device Tracker integration."""
from __future__ import annotations

from typing import Any

import voluptuous as vol

from homeassistant import config_entries
from homeassistant.data_entry_flow import FlowResult
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_LOCATION
from homeassistant.helpers.selector import LocationSelector

DOMAIN = "dummy_tracker"

class OptionsFlowHandler(config_entries.OptionsFlow):
"""Handle options flow for Dummy Device Tracker."""

def __init__(self, config_entry):
"""Initialize options flow."""
self.config_entry = config_entry

async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Manage the options."""
if user_input is not None:
lat: float = user_input[CONF_LOCATION][CONF_LATITUDE]
lon: float = user_input[CONF_LOCATION][CONF_LONGITUDE]

# Preserve the original entity name
entity_name = self.config_entry.data.get("entity_name", f"location_{lat}_{lon}")

return self.async_create_entry(
title=entity_name,
data={
CONF_LATITUDE: lat,
CONF_LONGITUDE: lon,
"entity_name": entity_name,
}
)

# Get current location from config entry
current_location = {
CONF_LATITUDE: self.config_entry.data[CONF_LATITUDE],
CONF_LONGITUDE: self.config_entry.data[CONF_LONGITUDE],
}

return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
vol.Required(
CONF_LOCATION,
default=current_location
): LocationSelector(),
}
),
)

0 comments on commit e17a09c

Please sign in to comment.