Skip to content

Commit

Permalink
Forecast fixes (#37)
Browse files Browse the repository at this point in the history
* Generate both daily and hourly forecast. The hourly forecast option has been removed.
  • Loading branch information
iprak authored Apr 18, 2024
1 parent cf02b4d commit 5e0bae8
Show file tree
Hide file tree
Showing 23 changed files with 250 additions and 244 deletions.
27 changes: 7 additions & 20 deletions .devcontainer/devcontainer.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,30 @@
"appPort": "9123:8123",
"containerUser": "root",
"remoteUser": "root",
"postCreateCommand": "scripts/setup.sh",
"postCreateCommand": "/container_content/scripts/setup.sh",
"initializeCommand": "docker image pull ghcr.io/iprak/custom-integration-image:main",
"containerEnv": {
"TZ": "America/Chicago"
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"esbenp.prettier-vscode",
"littlefoxteam.vscode-python-test-adapter",
"mhutchie.git-graph"
"charliermarsh.ruff",
"ms-python.pylint",
"ms-python.vscode-pylance"
],
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.blackPath": "/usr/local/bin/black",
"python.linting.pycodestylePath": "/usr/local/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/bin/pydocstyle",
"python.linting.mypyPath": "/usr/local/bin/mypy",
"python.linting.pylintPath": "/usr/local/bin/pylint",
"python.formatting.provider": "black",
"python.testing.pytestArgs": [
"--no-cov"
],
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true,
"files.eol": "\n",
"editor.tabSize": 4,
"python.analysis.autoSearchPaths": false,
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
}
}
}
}
Expand Down
17 changes: 2 additions & 15 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
# General files
.git
.github
config
docs

# Development
.devcontainer

# Test related files
tests

# Other virtualization methods
venv
.vagrant

# Temporary files
**/__pycache__
.vscode
**/__pycache__
15 changes: 13 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
* text=lf
*.py whitespace=error
# Ensure Docker script files uses LF to support Docker for Windows.
# Ensure "git config --global core.autocrlf input" before you clone
* text eol=lf
*.py whitespace=error

*.ico binary
*.jpg binary
*.png binary
*.zip binary
*.mp3 binary
*.pcm binary

Dockerfile.dev linguist-language=Dockerfile
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ share/*
/.dmypy.json

# These come from the image
setup.cfg
pyproject.toml
pylint/
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"charliermarsh.ruff",
"esbenp.prettier-vscode",
"ms-python.python"
]
}
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Home Assistant",
"type": "python",
"request": "launch",
"module": "homeassistant",
"justMyCode": false,
"args": [
"--debug",
"-c",
"/config"
],
"serverReadyAction": {
"action": "openExternally"
},
"console": "integratedTerminal"
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// Please keep this file in sync with settings in home-assistant/.devcontainer/devcontainer.json
"python.formatting.provider": "black",
// Added --no-cov to work around TypeError: message must be set
// https://github.com/microsoft/vscode-python/issues/14067
"python.testing.pytestArgs": ["--no-cov"],
// https://code.visualstudio.com/docs/python/testing#_pytest-configuration-settings
"python.testing.pytestEnabled": false
}
37 changes: 37 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Pytest",
"type": "shell",
"command": "pytest --timeout=10 tests",
"dependsOn": [
"Install all Test Requirements"
],
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": []
},
{
"label": "Pylint",
"type": "shell",
"command": "pylint custom_components",
"dependsOn": [],
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": []
},
]
}
27 changes: 10 additions & 17 deletions custom_components/weatherapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@
from datetime import timedelta
from typing import Final

from custom_components.weatherapi.const import (
CONFIG_FORECAST,
CONFIG_HOURLY_FORECAST,
CONFIG_IGNORE_PAST_HOUR,
DEFAULT_FORECAST,
DEFAULT_HOURLY_FORECAST,
DEFAULT_IGNORE_PAST_HOUR,
DOMAIN,
UPDATE_INTERVAL_MINUTES,
)
from custom_components.weatherapi.coordinator import (
WeatherAPIUpdateCoordinator,
WeatherAPIUpdateCoordinatorConfig,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_API_KEY,
Expand All @@ -27,6 +13,16 @@
)
from homeassistant.core import HomeAssistant

from .const import (
CONFIG_FORECAST,
CONFIG_IGNORE_PAST_HOUR,
DEFAULT_FORECAST,
DEFAULT_IGNORE_PAST_HOUR,
DOMAIN,
UPDATE_INTERVAL_MINUTES,
)
from .coordinator import WeatherAPIUpdateCoordinator, WeatherAPIUpdateCoordinatorConfig

PLATFORMS: Final = [Platform.WEATHER, Platform.SENSOR]


Expand All @@ -44,9 +40,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
name=entry.data[CONF_NAME],
update_interval=timedelta(minutes=UPDATE_INTERVAL_MINUTES),
forecast=entry.options.get(CONFIG_FORECAST, DEFAULT_FORECAST),
hourly_forecast=entry.options.get(
CONFIG_HOURLY_FORECAST, DEFAULT_HOURLY_FORECAST
),
ignore_past_forecast=entry.options.get(
CONFIG_IGNORE_PAST_HOUR, DEFAULT_IGNORE_PAST_HOUR
),
Expand Down
13 changes: 2 additions & 11 deletions custom_components/weatherapi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import voluptuous as vol

from custom_components.weatherapi.coordinator import CannotConnect, is_valid_api_key
from homeassistant import config_entries
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
from homeassistant.core import HomeAssistant, callback
Expand All @@ -14,14 +13,13 @@
from .const import ( # pylint:disable=unused-import
CONFIG_ADD_SENSORS,
CONFIG_FORECAST,
CONFIG_HOURLY_FORECAST,
CONFIG_IGNORE_PAST_HOUR,
DEFAULT_ADD_SENSORS,
DEFAULT_FORECAST,
DEFAULT_HOURLY_FORECAST,
DEFAULT_IGNORE_PAST_HOUR,
DOMAIN,
)
from .coordinator import CannotConnect, is_valid_api_key

_LOGGER = logging.getLogger(__name__)

Expand All @@ -41,7 +39,7 @@ def get_data_schema(hass: HomeAssistant) -> vol.Schema:
class OptionsFlowHandler(config_entries.OptionsFlow):
"""Handle options flow."""

def __init__(self, config_entry: config_entries.ConfigEntry):
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
"""Initialize options flow."""
self.config_entry = config_entry

Expand All @@ -66,13 +64,6 @@ async def async_step_init(self, user_input=None):
DEFAULT_FORECAST,
),
): bool,
vol.Required(
CONFIG_HOURLY_FORECAST,
default=self.config_entry.options.get(
CONFIG_HOURLY_FORECAST,
DEFAULT_HOURLY_FORECAST,
),
): bool,
vol.Required(
CONFIG_IGNORE_PAST_HOUR,
default=self.config_entry.options.get(
Expand Down
4 changes: 2 additions & 2 deletions custom_components/weatherapi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
ATTR_AIR_QUALITY_UK_DEFRA_INDEX_BAND: Final = "band"
ATTR_REPORTED_CONDITION: Final = "reported_condition"

DATA_FORECAST: Final = "forecast"
DAILY_FORECAST: Final = "daily_forecast"
HOURLY_FORECAST: Final = "hourly_forecast"

CONFIG_ADD_SENSORS: Final = "add_sensors"
CONFIG_FORECAST: Final = "forecast"
CONFIG_HOURLY_FORECAST: Final = "hourly_forecast"
CONFIG_IGNORE_PAST_HOUR: Final = "ignore_past_hour"

DEFAULT_ADD_SENSORS: Final = True
Expand Down
Loading

0 comments on commit 5e0bae8

Please sign in to comment.