Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #27 from thebino/Feature/custom_base_url
Browse files Browse the repository at this point in the history
add support for custom base url
  • Loading branch information
thebino authored Feb 15, 2021
2 parents 8a8ef0b + 55b0cfa commit 83bbcb7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions custom_components/rki_covid/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
class RKICovidAPI:
"""REST API for RKI Covid numbers."""

def __init__(self, session: ClientSession):
def __init__(self, session: ClientSession, baseurl: str = BASE_API_URL):
"""Initialize the REST API."""
self.session = session
self.baseurl = baseurl

async def load_districts(self) -> Iterable:
"""Return a specific district."""
response = await self.session.get(
url=f"{BASE_API_URL}{ENDPOINT_DISTRICTS}", allow_redirects=True
url=f"{self.baseurl}{ENDPOINT_DISTRICTS}", allow_redirects=True
)
if response.status == 200:
data = await response.json()
Expand Down
1 change: 1 addition & 0 deletions custom_components/rki_covid/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# configuration keywords
CONF_DISTRICTS = "districts"
CONF_COUNTY = "county"
CONF_BASEURL = "baseurl"

# configuration attributes
ATTR_COUNTY = "county"
Expand Down
1 change: 1 addition & 0 deletions custom_components/rki_covid/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"domain": "rki_covid",
"version": "1.4.1",
"name": "Robert-Koch Institut COVID Numbers",
"documentation": "https://github.com/thebino/rki_covid/blob/master/README.md",
"issue_tracker": "https://github.com/thebino/rki_covid/issues",
Expand Down
14 changes: 11 additions & 3 deletions custom_components/rki_covid/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from . import get_coordinator
from .api import RKICovidAPI
from .const import ATTRIBUTION, CONF_COUNTY, CONF_DISTRICTS
from .const import ATTRIBUTION, CONF_BASEURL, CONF_COUNTY, CONF_DISTRICTS

_LOGGER = logging.getLogger(__name__)

Expand All @@ -32,7 +32,10 @@

# schema for each platform sensor
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Required(CONF_DISTRICTS): vol.All(cv.ensure_list, [DISTRICT_SCHEMA])}
{
vol.Optional(CONF_BASEURL): str,
vol.Required(CONF_DISTRICTS): vol.All(cv.ensure_list, [DISTRICT_SCHEMA]),
}
)

SENSORS = {
Expand All @@ -56,7 +59,12 @@ async def async_setup_platform(
"""Set up the sensor platform."""
session = async_get_clientsession(hass)

api = RKICovidAPI(session)
if CONF_BASEURL in config:
baseurl = config[CONF_BASEURL]
_LOGGER.warning(f"You are using a custom base url: {baseurl}")
api = RKICovidAPI(session, baseurl)
else:
api = RKICovidAPI(session)
coordinator = await get_coordinator(hass, api)

districts = config[CONF_DISTRICTS]
Expand Down

0 comments on commit 83bbcb7

Please sign in to comment.