Compare commits
3 Commits
feature/va
...
v1.0.3-rc1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
216775e68f | ||
|
|
403efb937b | ||
|
|
559a463140 |
10
.github/workflows/python-app.yml
vendored
10
.github/workflows/python-app.yml
vendored
@@ -50,3 +50,13 @@ jobs:
|
|||||||
- name: Test with pytest
|
- name: Test with pytest
|
||||||
run: |
|
run: |
|
||||||
poetry run pytest
|
poetry run pytest
|
||||||
|
|
||||||
|
validate:
|
||||||
|
runs-on: "ubuntu-latest"
|
||||||
|
steps:
|
||||||
|
- uses: "actions/checkout@v2"
|
||||||
|
- name: HACS validation
|
||||||
|
uses: "hacs/action@main"
|
||||||
|
with:
|
||||||
|
category: "integration"
|
||||||
|
ignore: brands wheels
|
||||||
|
|||||||
@@ -67,9 +67,12 @@ async def get_coordinator(hass: HomeAssistant):
|
|||||||
if DOMAIN in hass.data:
|
if DOMAIN in hass.data:
|
||||||
return hass.data[DOMAIN]
|
return hass.data[DOMAIN]
|
||||||
|
|
||||||
async def async_get_data() -> IncidenceData:
|
async def async_get_data() -> dict:
|
||||||
crawler = CovidCrawler(hass)
|
crawler = CovidCrawler(hass)
|
||||||
return await crawler.crawl_incidence()
|
return {
|
||||||
|
"incidence": await crawler.crawl_incidence(),
|
||||||
|
"vaccination": await crawler.crawl_vaccination(),
|
||||||
|
}
|
||||||
|
|
||||||
hass.data[DOMAIN] = DataUpdateCoordinator(
|
hass.data[DOMAIN] = DataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://github.com/AdrianoKF/home-assistant-covid19-augsburg",
|
"documentation": "https://github.com/AdrianoKF/home-assistant-covid19-augsburg",
|
||||||
|
"issue_tracker": "https://github.com/AdrianoKF/home-assistant-covid19-augsburg/issues",
|
||||||
"requirements": ["beautifulsoup4==4.8.2"],
|
"requirements": ["beautifulsoup4==4.8.2"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@AdrianoKF"]
|
"codeowners": ["@AdrianoKF"]
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from dataclasses import asdict
|
||||||
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from . import get_coordinator
|
from . import get_coordinator
|
||||||
@@ -41,18 +43,59 @@ class CoronaAugsburgSensor(Entity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
return self.coordinator.data.incidence
|
return self.coordinator.data["incidence"].incidence
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
return {
|
data = self.coordinator.data["incidence"]
|
||||||
"date": self.coordinator.data.date,
|
return asdict(data)
|
||||||
"incidence": self.coordinator.data.incidence,
|
|
||||||
"total_cases": self.coordinator.data.total_cases,
|
async def async_added_to_hass(self):
|
||||||
"num_dead": self.coordinator.data.num_dead,
|
"""When entity is added to hass."""
|
||||||
"num_recovered": self.coordinator.data.num_recovered,
|
self.coordinator.async_add_listener(self.async_write_ha_state)
|
||||||
"num_infected": self.coordinator.data.num_infected,
|
|
||||||
}
|
async def async_will_remove_from_hass(self):
|
||||||
|
"""When entity will be removed from hass."""
|
||||||
|
self.coordinator.async_remove_listener(self.async_write_ha_state)
|
||||||
|
|
||||||
|
|
||||||
|
class CoronaAugsburgVaccinationSensor(Entity):
|
||||||
|
"""Representation of vaccination data for the city of Augsburg"""
|
||||||
|
|
||||||
|
def __init__(self, coordinator):
|
||||||
|
"""Initialize sensor."""
|
||||||
|
self.coordinator = coordinator
|
||||||
|
self._name = "COVID-19 Vaccinations Augsburg"
|
||||||
|
self._state = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
return self.coordinator.last_update_success and self.coordinator.data
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self):
|
||||||
|
return "mdi:biohazard"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unit_of_measurement(self):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self):
|
||||||
|
return self.coordinator.data["vaccination"].total_vaccinations
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
data = self.coordinator.data["vaccination"]
|
||||||
|
return asdict(data)
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""When entity is added to hass."""
|
"""When entity is added to hass."""
|
||||||
|
|||||||
Reference in New Issue
Block a user