Skip to content

Commit

Permalink
Merge branch 'main' into cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarwash committed Apr 13, 2024
2 parents f4e6a98 + 9acdad0 commit 7f49b2d
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 106 deletions.
125 changes: 60 additions & 65 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,65 @@
{
"image": "mcr.microsoft.com/vscode/devcontainers/python",
"name": "NOAA Space Weather integration development",
"postCreateCommand": "scripts/setup",
"postStartCommand": "hass --config /workspaces/home-assistant_noaa-space-weather/config/",
"forwardPorts": [
8123
],
"portsAttributes": {
"8123": {
"label": "Home Assistant"
},
"0-8122": {
"label": "Auto-Forwarded - Other",
"onAutoForward": "ignore"
},
"8124-999999": {
"label": "Auto-Forwarded - Other",
"onAutoForward": "ignore"
}
"image": "mcr.microsoft.com/vscode/devcontainers/python:3.12",
"name": "NOAA Space Weather integration development",
"postCreateCommand": "scripts/setup",
"postStartCommand": "hass --config /workspaces/home-assistant_noaa-space-weather/config/",
"forwardPorts": [8123],
"portsAttributes": {
"8123": {
"label": "Home Assistant"
},
"customizations": {
"extensions": [
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance"
],
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"files.eol": "\n",
"editor.tabSize": 4,
"python.pythonPath": "/usr/local/python/bin/python",
"python.analysis.autoSearchPaths": false,
"python.linting.pylintArgs": [
"--disable",
"import-error"
],
"python.formatting.provider": "black",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
},
"extensions": [
"github.vscode-pull-request-github",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vscode.makefile-tools",
"ryanluker.vscode-coverage-gutters"
]
}
"0-8122": {
"label": "Auto-Forwarded - Other",
"onAutoForward": "ignore"
},
"remoteUser": "vscode",
"features": {
"rust": "latest"
"8124-999999": {
"label": "Auto-Forwarded - Other",
"onAutoForward": "ignore"
}
},
"customizations": {
"extensions": [
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance"
],
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"files.eol": "\n",
"editor.tabSize": 4,
"python.pythonPath": "/usr/local/python/bin/python",
"python.analysis.autoSearchPaths": false,
"python.linting.pylintArgs": ["--disable", "import-error"],
"python.formatting.provider": "black",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
},
"extensions": [
"github.vscode-pull-request-github",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vscode.makefile-tools",
"ryanluker.vscode-coverage-gutters"
]
}
},
"remoteUser": "vscode",
"features": {
"rust": "latest"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/hacs-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- name: HACS validation
uses: "hacs/action@main"
with:
category: "integration"
category: "integration"
6 changes: 3 additions & 3 deletions .github/workflows/hassfest-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ on:
push:
pull_request:
schedule:
- cron: '0 0 * * *'
- cron: "0 0 * * *"

jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
- uses: "home-assistant/actions/hassfest@master"
- uses: "actions/checkout@v4"
- uses: "home-assistant/actions/hassfest@master"
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ repos:
language: system
types: [python]
require_serial: true
- id: reorder-python-imports
name: Reorder python imports
entry: reorder-python-imports
language: system
types: [python]
args: [--application-directories=custom_components]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.2.1
hooks:
Expand Down
4 changes: 4 additions & 0 deletions custom_components/noaa_space_weather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
For more details about this integration, please refer to
https://github.com/tcarwash/noaa_space_weather
"""

import asyncio
import logging
from datetime import timedelta

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import Config
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
Expand All @@ -25,6 +27,8 @@

_LOGGER: logging.Logger = logging.getLogger(__package__)

PLATFORM_SCHEMA = cv.platform_only_config_schema(DOMAIN)


async def async_setup(hass: HomeAssistant, config: Config):
"""Set up this integration using YAML is not supported."""
Expand Down
1 change: 1 addition & 0 deletions custom_components/noaa_space_weather/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sample API Client."""

import logging

import aiohttp
Expand Down
1 change: 1 addition & 0 deletions custom_components/noaa_space_weather/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow to configure the NOAA Space Weather integration."""

from __future__ import annotations

from typing import Any
Expand Down
1 change: 1 addition & 0 deletions custom_components/noaa_space_weather/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants for NOAA Space Weather."""

# Base component constants
NAME = "NOAA Space Weather"
DOMAIN = "noaa_space_weather"
Expand Down
1 change: 1 addition & 0 deletions custom_components/noaa_space_weather/entity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""NoaaSpaceWeatherEntity class"""

from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.components.image import ImageEntity

Expand Down
8 changes: 2 additions & 6 deletions custom_components/noaa_space_weather/manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
{
"domain": "noaa_space_weather",
"name": "NOAA Space Weather",
"codeowners": [
"@tcarwash"
],
"codeowners": ["@tcarwash"],
"config_flow": true,
"dependencies": [],
"documentation": "https://github.com/tcarwash/home-assistant_noaa-space-weather",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/tcarwash/home-assistant_noaa-space-weather/issues",
"requirements": [
"swpclib>=4.2.0"
],
"requirements": ["swpclib>=4.2.0"],
"version": "2.0.1"
}
20 changes: 14 additions & 6 deletions custom_components/noaa_space_weather/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sensor platform for NOAA Space Weather."""

from .const import DOMAIN
from .const import ICON
from .entity import NoaaSpaceWeatherEntity
Expand All @@ -13,14 +14,17 @@ def ai_return(coordinator):
if not coordinator.data.get("a_index_data") is None:
return coordinator.data.get("a_index_data", {}).get("a_index")


def ai_2d_return(coordinator):
if not coordinator.data.get("a_index_data") is None:
return coordinator.data.get("a_index_data", {}).get("a_2_day_index")


def ai_3d_return(coordinator):
if not coordinator.data.get("a_index_data") is None:
return coordinator.data.get("a_index_data", {}).get("a_3_day_index")


def kpi_return(coordinator):
if not coordinator.data.get("kp_index_data") is None:
return coordinator.data.get("kp_index_data", {}).get("kp_index")
Expand All @@ -42,9 +46,12 @@ def m1_return(coordinator):
if not coordinator.data.get("probabilities_data") is None:
return coordinator.data.get("probabilities_data", [{}])[0].get("m_class_1_day")


def polar_cap_absorption_return(coordinator):
if not coordinator.data.get("probabilities_data") is None:
return coordinator.data.get("probabilities_data", [{}])[0].get("polar_cap_absorption")
return coordinator.data.get("probabilities_data", [{}])[0].get(
"polar_cap_absorption"
)


async def async_setup_entry(hass, entry, async_add_devices):
Expand Down Expand Up @@ -118,15 +125,15 @@ def __init__(self, coordinator, entry, sensor):

@property
def state_class(self):
return self.sensor.get("state_class","measurement")
return self.sensor.get("state_class", "measurement")

@property
def unit_of_measurement(self):
return self.sensor.get('unit', '')
return self.sensor.get("unit", "")

@property
def options(self):
return self.sensor.get('options', None)
return self.sensor.get("options", None)

@property
def state(self):
Expand All @@ -137,7 +144,6 @@ def state(self):
else:
return None


@property
def unique_id(self):
return f"swpc {self.sensor['name']}"
Expand All @@ -164,4 +170,6 @@ def icon(self):
@property
def device_class(self):
"""Return the device class of the sensor."""
return self.sensor.get("device_class","noaa_space_weather__custom_device_class")
return self.sensor.get(
"device_class", "noaa_space_weather__custom_device_class"
)
24 changes: 11 additions & 13 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@
| -------- | ------------------- |
| `sensor` | Show info from API. |


**Currently available Sensors**

| Sensor | Description |
| ----------------------------------------- | ---------------------------------------------- |
| `sensor.ssn` | Current Sunspot Number. |
| `sensor.solar_flux_index` | Current Solar Flux Index. |
| `sensor.planetary_k_index` | Current Planetary K-Index. |
| `sensor.a_index` | Current A-Index. |
| `sensor.a_index_2_day` | 2-Day A-Index. |
| `sensor.a_index_3_day` | 3-Day A-Index. |
| `sensor.polar_cap_absorption` | A color-scale indication of polar cap absorption |
| `sensor.x_class_1_day_probability` | Probability of an X-Class flare within one day.|
| `sensor.m_class_1_day_probability` | Probability of an M-Class flare within one day.|

| Sensor | Description |
| ---------------------------------- | ------------------------------------------------ |
| `sensor.ssn` | Current Sunspot Number. |
| `sensor.solar_flux_index` | Current Solar Flux Index. |
| `sensor.planetary_k_index` | Current Planetary K-Index. |
| `sensor.a_index` | Current A-Index. |
| `sensor.a_index_2_day` | 2-Day A-Index. |
| `sensor.a_index_3_day` | 3-Day A-Index. |
| `sensor.polar_cap_absorption` | A color-scale indication of polar cap absorption |
| `sensor.x_class_1_day_probability` | Probability of an X-Class flare within one day. |
| `sensor.m_class_1_day_probability` | Probability of an M-Class flare within one day. |

![example][exampleimg]

Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-r requirements_dev.txt
pytest-homeassistant-custom-component==0.11.26
pytest-homeassistant-custom-component==0.13.113
2 changes: 1 addition & 1 deletion scripts/install/core
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -e
cd "$(dirname "$0")/../.."

bash scripts/install/pip_packages "homeassistant"
bash scripts/install/pip_packages "urllib3>=2.0.4"
#bash scripts/install/pip_packages "urllib3>=2.0.4"
9 changes: 9 additions & 0 deletions scripts/install/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

cd "$(dirname "$0")/../.."

ls

python -m pip install -r requirements_test.txt
1 change: 0 additions & 1 deletion scripts/install/pip_packages
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ python3 -m pip \
--upgrade \
--disable-pip-version-check \
"${@}"

2 changes: 1 addition & 1 deletion scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ scripts/install/core
rm -rf /workspaces/home-assistant_noaa-space-weather/config
hass --config $(pwd)/config --script ensure_config
ln -s /workspaces/home-assistant_noaa-space-weather/custom_components /workspaces/home-assistant_noaa-space-weather/config/custom_components

scripts/install/dev
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Global fixtures for NOAA Space Weather integration."""

from unittest.mock import patch

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test NOAA Space Weather config flow."""

from unittest.mock import patch

import pytest
Expand Down
Loading

0 comments on commit 7f49b2d

Please sign in to comment.