Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerbranda committed Mar 14, 2024
1 parent c0fdfa7 commit c9167aa
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 118 deletions.
6 changes: 4 additions & 2 deletions .storage/lovelace.dashboard_test
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
"cards": [
{
"type": "markdown",
"content": "{% set sensor = \"sensor.reeks\" %} {{states(sensor)}}\n-\n{% if state_attr(sensor, \"ranking\") != None %} {% for item in state_attr(sensor, \"ranking\") %} {{item.position}}. {% if item.id == state_attr(sensor, \"baseid\") %}**{{item.team}}** \n{% else %}{{item.team}} \n{% endif %} {%- endfor %} {% endif %}"
"content": "{% set sensor = \"sensor.reeks\" %} {{states(sensor)}}\n-\n{% if state_attr(sensor, \"ranking\") != None %} {% for item in state_attr(sensor, \"ranking\") %} {{item.position}}. {% if item.id == state_attr(sensor, \"baseid\") %}**{{item.team}}** \n{% else %}{{item.team}} \n{% endif %} {%- endfor %} {% endif %}",
"title": "Rangschikking"
},
{
"type": "markdown",
"content": "<table width=\"100%\">\n<tr>\n<th colspan=2>{{states('sensor.reeks')}}</th>\n</tr>\n<tr>\n<th colspan=2>\n<a href=\"https://www.rbfa.be/nl/wedstrijd/{{ states('sensor.rbfa_rbfa_upcoming_matchid_281445') }}\">{{as_timestamp(states('sensor.datum'))|timestamp_custom('%d-%m-%y om %H:%M')}}</a></th>\n</tr>\n<tr>\n<td align=\"center\"><img src=\"{{state_attr('sensor.thuis','entity_picture')}}\" width=\"64\"></td>\n<td align=\"center\"><img src=\"{{state_attr('sensor.uit','entity_picture')}}\" width=\"64\"></td>\n</tr>\n<tr>\n<td align=\"center\">{{states('sensor.thuis')}}</td>\n<td align=\"center\">{{states('sensor.uit')}}</td>\n</tr>\n<tr>\n<td align=\"center\">Positie: {{state_attr('sensor.thuis','position')}}</td>\n<td align=\"center\">Positie: {{state_attr('sensor.uit', 'position')}}</td>\n</tr>\n<tr>\n<td align=\"center\" colspan=\"2\">{{states('sensor.locatie') | replace(\"\\n\",\", \")}}</td>\n</tr>\n<tr>\n<td align=\"center\" colspan=\"2\">Scheidsrechter: {{states('sensor.rbfa_rbfa_upcoming_referee_281445') }}</td>\n</table>"
"content": "<table width=\"100%\">\n<tr>\n<th colspan=2>{{states('sensor.reeks')}}</th>\n</tr>\n<tr>\n<th colspan=2>\n<a href=\"https://www.rbfa.be/nl/wedstrijd/{{ states('sensor.rbfa_rbfa_upcoming_matchid_281445') }}\">{{as_timestamp(states('sensor.datum'))|timestamp_custom('%d-%m-%y om %H:%M uur')}}</a></th>\n</tr>\n<tr>\n<td align=\"center\"><img src=\"{{state_attr('sensor.thuis','entity_picture')}}\" width=\"64\"></td>\n<td align=\"center\"><img src=\"{{state_attr('sensor.uit','entity_picture')}}\" width=\"64\"></td>\n</tr>\n<tr>\n<td align=\"center\">{{states('sensor.thuis')}}</td>\n<td align=\"center\">{{states('sensor.uit')}}</td>\n</tr>\n<tr>\n<td align=\"center\">Positie: {{state_attr('sensor.thuis','position')}}</td>\n<td align=\"center\">Positie: {{state_attr('sensor.uit', 'position')}}</td>\n</tr>\n<tr>\n<td align=\"center\" colspan=\"2\">{{states('sensor.locatie') | replace(\"\\n\",\", \")}}</td>\n</tr>\n<tr>\n<td align=\"center\" colspan=\"2\">Scheidsrechter: {{states('sensor.rbfa_rbfa_upcoming_referee_281445') }}</td>\n</table>",
"title": "Wedstrijdfiche"
}
]
}
Expand Down
2 changes: 0 additions & 2 deletions custom_components/rbfa/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ async def update(self):


summary = '[' + item['state'] + '] ' + item['homeTeam']['name'] + ' - ' + item['awayTeam']['name']
# if item['state'] == 'postponed':
# summary = '[postponed] ' + summary

result = 'No match score'
if item['outcome']['homeTeamGoals'] != None:
Expand Down
68 changes: 2 additions & 66 deletions custom_components/rbfa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,22 @@
"""
Example config:
Configuration.yaml:
rbra:
team: 123456
"""
#from __future__ import annotations

import logging
#from datetime import datetime
from datetime import timedelta
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform

from homeassistant.core import HomeAssistant
#from homeassistant.helpers.typing import ConfigType
from homeassistant.components import persistent_notification

from .const import DOMAIN, CONF_TEAM, CONF_UPDATE_INTERVAL
from .const import DOMAIN
from .API import TeamApp

from .coordinator import MyCoordinator


__version__ = "0.1"


_LOGGER = logging.getLogger(__name__)

PLATFORMS = [Platform.CALENDAR, Platform.SENSOR]

'''
async def async_setup(hass: HomeAssistant, config: ConfigType):
_LOGGER.debug("Setup of RBFA component Rest API retriever")
config = config.get(DOMAIN, None)
if config is None:
_LOGGER.debug("config not found")
return True
if not isinstance(config, list):
config = [config]
for conf in config:
_LOGGER.debug('configuration: %r', conf)
if conf[CONF_TEAM] != "":
team = conf.get(CONF_TEAM)
update_interval = conf.get(CONF_UPDATE_INTERVAL)
data = TeamData(hass, team, update_interval)
hass.data.setdefault(DOMAIN, {})[team] = data
hass.helpers.discovery.load_platform(
Platform.CALENDAR, DOMAIN, {"config": conf}, conf
)
# hass.helpers.discovery.load_platform(
# Platform.SENSOR, DOMAIN, {"config": conf}, conf
# )
_LOGGER.debug("data schedule update")
await data.schedule_update(timedelta())
else:
persistent_notification.create(
hass,
"Config invalid! Team id is required",
"RBFA",
DOMAIN + "_invalid_config",
)
return True
'''

async def async_setup_entry(hass, entry) -> bool:
"""Set up Elgato Light from a config entry."""
"""Set up RBFA from a config entry."""
coordinator = MyCoordinator(hass, entry)
_LOGGER.debug('first refresh')
await coordinator.async_config_entry_first_refresh()
Expand All @@ -84,8 +25,3 @@ async def async_setup_entry(hass, entry) -> bool:
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True

#async def async_update_options(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
# """Update options."""
# await hass.config_entries.async_reload(config_entry.entry_id)

3 changes: 1 addition & 2 deletions custom_components/rbfa/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from datetime import datetime, timedelta
from typing import Optional, List

#from homeassistant.const import CONF_RESOURCES
from homeassistant.core import HomeAssistant
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -21,7 +20,7 @@ async def async_setup_entry(
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Elgato sensor based on a config entry."""
"""Set up RBFA sensor based on a config entry."""
coordinator: MyCoordinator = hass.data[DOMAIN][entry.entry_id]

async_add_entities(
Expand Down
4 changes: 2 additions & 2 deletions custom_components/rbfa/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import voluptuous as vol


class ExampleConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
class RbfaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Example config flow."""
# The schema version of the entries that it creates
# Home Assistant will call your migrate method if the version changes
Expand All @@ -24,6 +24,6 @@ async def async_step_user(self, user_input):


return self.async_show_form(
step_id="user",
step_id="user",
data_schema=vol.Schema({vol.Required('team'): str}),
)
12 changes: 0 additions & 12 deletions custom_components/rbfa/const.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from datetime import timedelta, time
import voluptuous as vol

import homeassistant.helpers.config_validation as cv
#from homeassistant.const import CONF_RESOURCES

import json
from pathlib import Path

Expand All @@ -16,12 +10,6 @@
NAME = manifest_data.get("name")
VERSION = manifest_data.get("version")

SCHEDULE_UPDATE_INTERVAL = timedelta(minutes=5) # hours=12

CONF_TEAM = 'team'
CONF_RESULT = 'result'
CONF_UPDATE_INTERVAL = 'updateinterval'

TZ = 'Europe/Brussels'

VARIABLES = {
Expand Down
2 changes: 1 addition & 1 deletion custom_components/rbfa/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"dependencies": [],
"codeowners": ["@rgerbranda"],
"requirements": [],
"version": "v0.1.3"
"version": "v0.1.4"
}
36 changes: 5 additions & 31 deletions custom_components/rbfa/sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Platform for sensor integration."""
from __future__ import annotations
#from collections.abc import Callable
#from dataclasses import dataclass

from homeassistant.components.sensor import (
SensorDeviceClass,
Expand All @@ -10,27 +8,15 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
#from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

#from homeassistant.const import Platform
from .const import DOMAIN, CONF_TEAM

#from .API import TeamData

from .const import DOMAIN
from .coordinator import MyCoordinator
from .entity import RbfaEntity

import logging

_LOGGER = logging.getLogger(__name__)

# @dataclass(frozen=True, kw_only=True)
# class RbfaSensorEntityDescription(SensorEntityDescription):
# """A class that describes AEMET OpenData sensor entities."""
#
# keys: list[str] | None = None
# value_fn: Callable[[str], datetime | float | int | str | None] = lambda value: value

SENSORS = (
SensorEntityDescription(
key="date",
Expand All @@ -48,11 +34,12 @@
SensorEntityDescription(
key="location",
translation_key="location",
icon="mdi:map-marker",
icon="mdi:soccer-field",
),
SensorEntityDescription(
key="series",
translation_key="series",
icon="mdi:table-row",
),
SensorEntityDescription(
key="referee",
Expand All @@ -62,29 +49,16 @@
SensorEntityDescription(
key="matchid",
translation_key="matchid",
icon="mdi:soccer",
),
# SensorEntityDescription(
# key="position",
# translation_key="position",
# ),
# RbfaSensorEntityDescription(
# key="hometeamgoals",
# translation_key="hometeamgoals",
# icon = "mdi:scoreboard"
# ),
# RbfaSensorEntityDescription(
# key="awayteamgoals",
# translation_key="awayteamgoals",
# icon = "mdi:scoreboard"
# ),
)

async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Elgato sensor based on a config entry."""
"""Set up RBFA sensor based on a config entry."""
coordinator: MyCoordinator = hass.data[DOMAIN][entry.entry_id]

all_sensors = []
Expand Down
3 changes: 3 additions & 0 deletions custom_components/rbfa/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
},
"id":{
"name":"Team ID"
},
"ranking":{
"name":"Rangschikking"
}
}
}
Expand Down

0 comments on commit c9167aa

Please sign in to comment.