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

add weather entity and extra wind dir sensors #38

Merged
merged 4 commits into from
Sep 10, 2023
Merged
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ WORKDIR /srv/homeassistant
RUN python -m venv . \
&& source bin/activate \
&& python -m pip install wheel \
&& pip3 install homeassistant
&& pip3 install urllib3==1.26.7 homeassistant

RUN ./setup.sh

Expand Down
18 changes: 4 additions & 14 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,8 @@
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/srv/homeassistant/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.formatting.provider": "black",
"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",
"python.linting.pylintArgs": [
"pylint.path": ["/usr/local/py-utils/bin/pylint"],
"pylint.args": [
"--init-hook",
"import sys; sys.path.append('/srv/homeassistant/lib/python3.11/site-packages/')"
],
Expand All @@ -51,7 +40,8 @@
"esbenp.prettier-vscode",
"GitHub.vscode-pull-request-github",
"streetsidesoftware.code-spell-checker",
"ms-python.pylint"
"ms-python.pylint",
"ms-python.black-formatter"
]
}
},
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.python"
"editor.defaultFormatter": "ms-python.black-formatter"
},
"editor.rulers": [100],
"rewrap.autoWrap.enabled": true,
"rewrap.wrappingColumn": 100,
"python.formatting.provider": "black",
"cSpell.words": ["awnet", "hass", "homeassistant"]
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog],
and this project adheres to [Semantic Versioning].

## [1.2.0] - 2023-09-09

### Added

- The following calculated sensors have been added:
- Wind Direction Cardinal
- Gust Direction Cardinal
- BETA: added a weather entity to collect common data in one place and loosely predict the weather
condition outside based on data available from the sensor array. The weather condition part of
this entity is currently in testing. Please raise issues for any unexpected behavior.

## [1.1.3] - 2023-07-13

### Fixed
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ Configuration is performed via the Home Assistant user interface. You will need
- Name: a friendly name for the device to display in Home Assistant
- MAC: the MAC address for the device

Once configured, setup the accompanying add-on [AWNET](https://github.com/tlskinneriv/hassio-addons/tree/master/awnet) (see the [docs](https://github.com/tlskinneriv/hassio-addons/blob/master/awnet/DOCS.md) for direct instructions).
Once configured, setup the accompanying add-on
[AWNET](https://github.com/tlskinneriv/hassio-addons/tree/master/awnet) (see the
[docs](https://github.com/tlskinneriv/hassio-addons/blob/master/awnet/DOCS.md) for direct
instructions).

> NOTE: Entities for the device will not show up until the add-on referenced above is installed and
> the settings are properly configured on the Ambient Weather device. Currently, the integration
> supports only one weather station.

## Service

Expand Down
2 changes: 1 addition & 1 deletion custom_components/awnet_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

_LOGGER = logging.getLogger(__name__)

PLATFORMS = [Platform.SENSOR, Platform.BINARY_SENSOR]
PLATFORMS = [Platform.SENSOR, Platform.BINARY_SENSOR, Platform.WEATHER]
STORAGE_KEY = DOMAIN + "_data"
STORAGE_VERSION = 1

Expand Down
20 changes: 18 additions & 2 deletions custom_components/awnet_local/const_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@
TYPE_UV = "uv"
TYPE_WEEKLYRAININ = "weeklyrainin"
TYPE_WINDDIR = "winddir"
TYPE_WINDDIR_CARD = "winddir_card"
TYPE_WINDDIR_AVG10M = "winddir_Avg10m"
TYPE_WINDDIR_AVG2M = "winddir_Avg2m"
TYPE_WINDGUSTDIR = "windgustdir"
TYPE_WINDGUSTDIR_CARD = "windgustdir_card"
TYPE_WINDGUSTMPH = "windgustmph"
TYPE_WINDSPDMPH_AVG10M = "windspdmph_Avg10m"
TYPE_WINDSPDMPH_AVG2M = "windspdmph_Avg2m"
Expand Down Expand Up @@ -264,7 +266,9 @@
TYPE_WINDDIR_AVG10M,
TYPE_WINDDIR_AVG2M,
TYPE_WINDDIR,
TYPE_WINDDIR_CARD,
TYPE_WINDGUSTDIR,
TYPE_WINDGUSTDIR_CARD,
TYPE_WINDGUSTMPH,
TYPE_WINDSPDMPH_AVG10M,
TYPE_WINDSPDMPH_AVG2M,
Expand All @@ -282,6 +286,8 @@
TYPE_FEELSLIKE_IN: [TYPE_TEMPINF, TYPE_HUMIDITYIN],
TYPE_DEWPOINT_IN: [TYPE_TEMPINF, TYPE_HUMIDITYIN],
TYPE_LIGHTNING_PER_HOUR: [TYPE_LIGHTNING_PER_DAY, TYPE_DATEUTC],
TYPE_WINDDIR_CARD: [TYPE_WINDDIR],
TYPE_WINDGUSTDIR_CARD: [TYPE_WINDGUSTDIR],
}

# Each sensor listed here is converted server-side from the native unit to the unit that HA supports
Expand Down Expand Up @@ -1069,11 +1075,16 @@
),
SensorEntityDescription(
key=TYPE_WINDDIR,
name="Wind Dir",
name="Wind Direction",
icon="mdi:weather-windy",
native_unit_of_measurement=DEGREE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=TYPE_WINDDIR_CARD,
name="Wind Direction Cardinal",
icon="mdi:weather-windy",
),
SensorEntityDescription(
key=TYPE_WINDDIR_AVG10M,
name="Wind Dir Avg 10m",
Expand All @@ -1090,11 +1101,16 @@
),
SensorEntityDescription(
key=TYPE_WINDGUSTDIR,
name="Gust Dir",
name="Gust Direction",
icon="mdi:weather-windy",
native_unit_of_measurement=DEGREE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=TYPE_WINDGUSTDIR_CARD,
name="Gust Direction Cardinal",
icon="mdi:weather-windy",
),
SensorEntityDescription(
key=TYPE_WINDGUSTMPH,
name="Wind Gust",
Expand Down
43 changes: 43 additions & 0 deletions custom_components/awnet_local/helpers_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
TYPE_LIGHTNING_PER_HOUR,
TYPE_LIGHTNING_PER_DAY,
TYPE_DATEUTC,
TYPE_WINDDIR,
TYPE_WINDDIR_CARD,
TYPE_WINDGUSTDIR,
TYPE_WINDGUSTDIR_CARD,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -87,6 +91,14 @@ def calculate(entity_key: str, station_data: dict[str, object]) -> object:
int(station_values.get(TYPE_LIGHTNING_PER_DAY)),
station_data[ATTR_LIGHTNING_DATA],
)
if entity_key == TYPE_WINDDIR_CARD:
return AmbientSensorCalculations.degree_to_cardinal(
float(station_values.get(TYPE_WINDDIR))
)
if entity_key == TYPE_WINDGUSTDIR_CARD:
return AmbientSensorCalculations.degree_to_cardinal(
float(station_values.get(TYPE_WINDGUSTDIR))
)
raise NotImplementedError(f"Calculation for {entity_key} is not implemented")

@staticmethod
Expand Down Expand Up @@ -291,6 +303,37 @@ def dew_point(tempf: float, rel_humid_percent: float) -> float:
dew_pt_c = (const_c * gamma_t_rh) / (const_b - gamma_t_rh)
return float(round(dew_pt_c * 9 / 5 + 32, 1))

@staticmethod
def degree_to_cardinal(direction_degree: float) -> str:
"""Converts a direction in degrees to its cardinal equivalent

Args:
direction_degree (float): Direction in degrees

Returns:
str: Cardinal direction
"""
direction = [
"N",
"NNE",
"NE",
"ENE",
"E",
"ESE",
"SE",
"SSE",
"S",
"SSW",
"SW",
"WSW",
"W",
"WNW",
"NW",
"NNW",
"N",
]
return direction[int((direction_degree + 11.25) / 22.5)]


class AmbientSensorConversions:
"""Class full of static methods for performing conversions from native units to HA units where
Expand Down
8 changes: 5 additions & 3 deletions custom_components/awnet_local/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"domain": "awnet_local",
"name": "Ambient Weather Station - Local",
"codeowners": ["@tlskinneriv"],
"codeowners": [
"@tlskinneriv"
],
"config_flow": true,
"dependencies": [],
"documentation": "https://github.com/tlskinneriv/awnet_local",
"integration_type": "device",
"iot_class": "local_push",
"issue_tracker": "https://github.com/tlskinneriv/awnet_local/issues",
"requirements": [],
"version": "1.1.3"
}
"version": "1.2.0"
}
Loading