Skip to content

Commit

Permalink
Merge pull request #21 from PiotrMachowski/dev
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
PiotrMachowski authored Jul 13, 2023
2 parents 3567e51 + ff2e413 commit 3ddccc3
Show file tree
Hide file tree
Showing 14 changed files with 834 additions and 225 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/hacs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/setup-python@v2
name: Setup Python
with:
python-version: '3.8.x'
python-version: '3.11.x'

- uses: actions/cache@v2
name: Cache
Expand All @@ -26,4 +26,5 @@ jobs:
- name: HACS Action
uses: hacs/action@main
with:
CATEGORY: integration
CATEGORY: integration
ignore: brands
60 changes: 15 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,28 @@

# Burze.dzis.net sensor

This sensor uses official API to get weather warnings from [*Burze.dzis.net*](https://burze.dzis.net/). To get more detailed information about parameters of warnings visit [*official API documentation*](https://burze.dzis.net/soap.php?WSDL).
This integration uses official API to get weather warnings from [*Burze.dzis.net*](https://burze.dzis.net/).

## Configuration options
It retrieves following data:
- frost hazard
- heat hazard
- wind hazard
- precipitation hazard
- storm hazard
- tornado hazard
- detected lightnings
- gamma radiation level (for Warsaw)

| Key | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `string` | `False` | `Burze.dzis.net` | Name of sensor |
| `api_key` | `string` | `True` | - | API key for Burze.dzis.net |
| `latitude` | `float` | `False` | Latitude of home | Latitude of monitored point |
| `longitude` | `float` | `False` | Longitude of home | Longitude of monitored point |
| `warnings` | `list` | `False` | - | List of monitored warnings |
| `storms_nearby` | - | `False` | - | Enables monitoring nearby storms |
To get more detailed information about parameters of warnings you can check out [*official API documentation*](https://burze.dzis.net/soap.php?WSDL).

### Configuration options of `storms_nearby`
## Configuration

| Key | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `radius` | `positive int` | `True` | - | Radius of nearby storms monitoring |
To configure this integration go to: _Configuration_ -> _Integrations_ -> _Add integration_ -> _Burze.dzis.net_.

### Possible monitored warnings
You can also use following [My Home Assistant](http://my.home-assistant.io/) link:

| Key | Description |
| --- | --- |
| `frost_warning` | Enables frost warnings monitoring |
| `heat_warning` | Enables heat warnings monitoring |
| `wind_warning` | Enables wind warnings monitoring |
| `precipitation_warning` | Enables precipitation warnings monitoring |
| `storm_warning` | Enables storm warnings monitoring |
| `tornado_warning` | Enables tornado warnings monitoring |
[![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=burze_dzis_net)

## Example usage

```
binary_sensor:
- platform: burze_dzis_net
api_key: !secret burze_dzis_net.api_key
warnings:
- frost_warning
- heat_warning
- wind_warning
- precipitation_warning
- storm_warning
- tornado_warning
storms_nearby:
radius: 30
```

## Installation

Expand All @@ -90,12 +66,6 @@ rm burze_dzis_net.zip

To get API key you have to follow steps available at [*official project page*](https://burze.dzis.net/?page=api_interfejs).

* **What to do if Home Assistant does not find this component?**

Most likely you have to install additional dependency required for it to run. Activate Python environment Home Assistant is running in and use following command:
```bash
pip install zeep
```


<!-- piotrmachowski_support_links_start -->
Expand Down
67 changes: 66 additions & 1 deletion custom_components/burze_dzis_net/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
"""Burze.dzis.net"""
import logging

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_RADIUS
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady

from .const import (
CONF_USE_HOME_COORDINATES, DOMAIN, PLATFORMS,
)
from .update_coordinator import BurzeDzisNetUpdateCoordinator

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_API_KEY): cv.string,
vol.Required(CONF_LONGITUDE): cv.positive_float,
vol.Required(CONF_LATITUDE): cv.positive_float,
vol.Required(CONF_RADIUS): cv.positive_int,
vol.Required(CONF_USE_HOME_COORDINATES): cv.boolean,
}
)


async def async_setup(hass, config):
return True


async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
if hass.data.get(DOMAIN) is None:
hass.data.setdefault(DOMAIN, {})

api_key = config_entry.data.get(CONF_API_KEY)
longitude = config_entry.data.get(CONF_LONGITUDE)
latitude = config_entry.data.get(CONF_LATITUDE)
radius = config_entry.data.get(CONF_RADIUS)

coordinator = BurzeDzisNetUpdateCoordinator(hass, api_key, latitude, longitude, radius)
await coordinator.async_refresh()

if not coordinator.last_update_success:
raise ConfigEntryNotReady

hass.data[DOMAIN][config_entry.entry_id] = coordinator

await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
config_entry.async_on_unload(config_entry.add_update_listener(async_reload_entry))
return True


async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Unload a config entry."""
unloaded = await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
if unloaded:
hass.data[DOMAIN].pop(config_entry.entry_id)
return unloaded


async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Reload config entry."""
await async_unload_entry(hass, entry)
await async_setup_entry(hass, entry)
Loading

0 comments on commit 3ddccc3

Please sign in to comment.