Skip to content

Commit

Permalink
feat: configure integration from ui
Browse files Browse the repository at this point in the history
  • Loading branch information
chilikla authored Oct 23, 2024
1 parent b805a5c commit 2833eb0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 72 deletions.
30 changes: 15 additions & 15 deletions custom_components/yerushamayim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
from .const import DOMAIN
from .data_coordinator import YerushamayimDataCoordinator

# PLATFORMS: list[Platform] = [Platform.SENSOR]
PLATFORMS: list[Platform] = [Platform.SENSOR]

# async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# """Set up Yerushamayim from a config entry."""
# coordinator = YerushamayimDataCoordinator(hass)
# await coordinator.async_config_entry_first_refresh()
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Yerushamayim from a config entry."""
coordinator = YerushamayimDataCoordinator(hass)
await coordinator.async_config_entry_first_refresh()

# hass.data.setdefault(DOMAIN, {})
# hass.data[DOMAIN][entry.entry_id] = coordinator
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = coordinator

# await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
# return True
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."""
# unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
# if unload_ok:
# hass.data[DOMAIN].pop(entry.entry_id)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)

# return unload_ok
return unload_ok
81 changes: 24 additions & 57 deletions custom_components/yerushamayim/weather.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,52 @@
"""Support for Yerushamayim weather service."""
"""Weather platform for Yerushamayim integration."""
from __future__ import annotations

from homeassistant.components.weather import (
WeatherEntity,
Forecast,
WeatherEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
UnitOfTemperature
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import DOMAIN
from .data_coordinator import YerushamayimDataCoordinator

async def async_setup_entry(
async def async_setup_platform(
hass: HomeAssistant,
entry: ConfigEntry,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up Yerushamayim weather based on a config entry."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_entities([YerushamayimWeather(coordinator)], False)
coordinator = hass.data[DOMAIN]
async_add_entities([YerushamayimWeather(coordinator)], True)

class YerushamayimWeather(CoordinatorEntity, WeatherEntity):
"""Representation of Yerushamayim weather data."""

_attr_has_entity_name = True
_attr_name = None
_attr_supported_features = WeatherEntityFeature.FORECAST_DAILY

def __init__(self, coordinator: DataUpdateCoordinator) -> None:
"""Initialize the Yerushamayim weather entity."""
def __init__(self, coordinator: YerushamayimDataCoordinator):
super().__init__(coordinator)
self._attr_unique_id = f"{DOMAIN}_weather"
self._attr_name = "Yerushamayim Weather"

@property
def native_temperature(self) -> float | None:
"""Return the temperature."""
return self.coordinator.data.get("current_temp")

@property
def native_temperature_unit(self) -> str:
"""Return the unit of measurement."""
return "°C"
def native_temperature(self) -> float:
return float(self.coordinator.data.temperature["temperature"])

@property
def humidity(self) -> float | None:
"""Return the humidity."""
# TODO: Implement if available
return None
def native_apparent_temperature(self) -> float:
return float(self.coordinator.data.temperature["apparent_temperature"])

@property
def wind_speed(self) -> float | None:
"""Return the wind speed."""
# TODO: Implement if available
return None

@property
def wind_bearing(self) -> float | str | None:
"""Return the wind bearing."""
# TODO: Implement if available
return None

@property
def attribution(self) -> str:
"""Return the attribution."""
return "Data provided by Yerushamayim Weather Service"
def native_temperature_unit(self) -> str:
return UnitOfTemperature.CELSIUS

@property
def condition(self) -> str | None:
"""Return the current condition."""
# TODO: Map the condition to HA states
return None
def humidity(self) -> float:
return float(self.coordinator.data.humidity["humidity"])

@property
def forecast(self) -> list[Forecast] | None:
"""Return the forecast."""
# TODO: Implement forecast data
return None

# TODO: Implement other relevant properties and methods
def condition(self) -> str:
return self.coordinator.data.status["forecast"]

0 comments on commit 2833eb0

Please sign in to comment.