Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement basic UI setup #179

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,21 @@ sensor:
test_humidity:
# unit_of_measurement: "%"
value_template: "{{ 43 }}"
# device_class: humidity
device_class: humidity

input_boolean:
dummy_heater:
name: "Dummy Heater"

climate:
- platform: generic_thermostat
name: "Template Climate"
heater: switch.dummy_heater # Create or use a dummy switch
target_sensor: sensor.test_temperature
min_temp: 15
max_temp: 30
ac_mode: false
target_temp: 22.5
cold_tolerance: 0.5
hot_tolerance: 0.5
initial_hvac_mode: "heat"
22 changes: 22 additions & 0 deletions custom_components/apparent_temperature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,25 @@
For more details about this integration, please refer to
https://github.com/Limych/ha-temperature-feeling
"""

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant

from .const import DOMAIN


async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Handle setup of config entry."""
hass.data.setdefault(DOMAIN, {})

await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.SENSOR]
)

return True


async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle removal of a config entry."""
hass.data[DOMAIN].pop(entry.entry_id, None)
144 changes: 144 additions & 0 deletions custom_components/apparent_temperature/config_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
"""Homeassistant Config Flow for integration."""

from typing import Any

import voluptuous as vol
from homeassistant import config_entries
from homeassistant.config_entries import (
ConfigFlowResult,
)
from homeassistant.helpers.selector import selector

from .const import DOMAIN

MANUAL_SETUP_SCHEMA = vol.Schema(
{
vol.Required("name"): str,
vol.Required("temperature"): selector(
{"entity": {"domain": "sensor", "device_class": "temperature"}}
),
vol.Required("humidity"): selector(
{"entity": {"domain": "sensor", "device_class": "humidity"}}
),
vol.Optional("wind_speed"): selector(
{"entity": {"domain": "sensor", "device_class": "wind_speed"}}
),
}
)

WEATHER_SETUP_SCHEMA = vol.Schema(
{
vol.Required("name"): str,
vol.Required("weather"): selector({"entity": {"domain": "weather"}}),
}
)

CLIMATE_SETUP_SCHEMA = vol.Schema(
{
vol.Required("name"): str,
vol.Required("climate"): selector({"entity": {"domain": "climate"}}),
}
)

USER_STEP_TYPE = "type"
USER_STEP_TYPE_MANUAL_OPTION = "type_manual"
USER_STEP_TYPE_WEATHER_OPTION = "type_weather"
USER_STEP_TYPE_CLIMATE_OPTION = "type_climate"

USER_STEP_SCHEMA = vol.Schema(
{
vol.Required(USER_STEP_TYPE): selector(
{
"select": {
"options": [
{
"value": USER_STEP_TYPE_MANUAL_OPTION,
"label": "Manual",
},
{
"value": USER_STEP_TYPE_WEATHER_OPTION,
"label": "Weather entity",
},
{
"value": USER_STEP_TYPE_CLIMATE_OPTION,
"label": "Climate entity",
},
],
"mode": "list",
}
}
)
}
)


class ApparentTemperatureConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Example config flow."""

VERSION = 1
MINOR_VERSION = 1

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Set up integration."""
errors: dict[str, str] = {}

if user_input is not None:
user_step_type = user_input[USER_STEP_TYPE]
if user_step_type == USER_STEP_TYPE_MANUAL_OPTION:
return await self.async_step_manual_config()

if user_step_type == USER_STEP_TYPE_WEATHER_OPTION:
return await self.async_step_weather_config()

if user_step_type == USER_STEP_TYPE_CLIMATE_OPTION:
return await self.async_step_climate_config()

errors[USER_STEP_TYPE] = "Not supported"

return self.async_show_form(
step_id="user", data_schema=USER_STEP_SCHEMA, errors=errors
)

async def async_step_climate_config(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Set up integration for climate entity."""
if user_input is not None:
return self.async_create_entry(
title=user_input["name"],
data=user_input,
)

return self.async_show_form(
step_id="climate_config", data_schema=CLIMATE_SETUP_SCHEMA
)

async def async_step_weather_config(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Set up integration for weather entity."""
if user_input is not None:
return self.async_create_entry(
title=user_input["name"],
data=user_input,
)

return self.async_show_form(
step_id="weather_config", data_schema=WEATHER_SETUP_SCHEMA
)

async def async_step_manual_config(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Set up integration manually, using provided entities."""
if user_input is not None:
return self.async_create_entry(
title=user_input["name"],
data=user_input,
)

return self.async_show_form(
step_id="manual_config", data_schema=MANUAL_SETUP_SCHEMA
)
2 changes: 1 addition & 1 deletion custom_components/apparent_temperature/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"codeowners": [
"@Limych"
],
"config_flow": false,
"config_flow": true,
"dependencies": [],
"documentation": "https://github.com/Limych/ha-apparent-temperature",
"iot_class": "calculated",
Expand Down
Loading
Loading