Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Lindvig authored Jun 20, 2022
1 parent 039ca08 commit 7236fce
Show file tree
Hide file tree
Showing 5 changed files with 562 additions and 558 deletions.
61 changes: 32 additions & 29 deletions custom_components/fuelprices_dk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,42 @@
from .fuelprices_dk_api import fuelprices

from .const import (
DOMAIN,
CONF_CLIENT,
CONF_FUELCOMPANIES,
CONF_FUELTYPES,
CONF_PLATFORM,
DOMAIN,
CONF_CLIENT,
CONF_FUELCOMPANIES,
CONF_FUELTYPES,
CONF_PLATFORM,
)

_LOGGER: logging.Logger = logging.getLogger(__package__)
_LOGGER = logging.getLogger(__name__)


async def async_setup(hass, config):
# Get the configuration
conf = config.get(DOMAIN)
# If no config, abort
if conf is None:
return True

# Extract companies and fuueltypes from the config, defult to empty list
fuelCompanies = conf.get(CONF_FUELCOMPANIES, [])
fuelTypes = conf.get(CONF_FUELTYPES, [])

# Initialize a instance of the fuelprices API
fuelPrices = fuelprices()
# Load the data using the config
fuelPrices.loadCompanies(fuelCompanies, fuelTypes)
# Store the client in the hass data stack
hass.data[DOMAIN] = {CONF_CLIENT: fuelPrices}

# Add sensors
hass.async_create_task(
hass.helpers.discovery.async_load_platform(CONF_PLATFORM, DOMAIN, conf, config)
)

# Initialization was successful.
return True
# Get the configuration
conf = config.get(DOMAIN)
# If no config, abort
if conf is None:
return True

# Extract companies and fuueltypes from the config, defult to empty list
fuelCompanies = conf.get(CONF_FUELCOMPANIES, [])
fuelTypes = conf.get(CONF_FUELTYPES, [])

_LOGGER.debug("fuelCompanies: " + str(fuelCompanies))
_LOGGER.debug("fuelTypes: " + str(fuelTypes))

# Initialize a instance of the fuelprices API
fuelPrices = fuelprices()
# Load the data using the config
fuelPrices.loadCompanies(fuelCompanies, fuelTypes)
# Store the client in the hass data stack
hass.data[DOMAIN] = {CONF_CLIENT: fuelPrices}

# Add sensors
hass.async_create_task(
hass.helpers.discovery.async_load_platform(CONF_PLATFORM, DOMAIN, conf, config)
)

# Initialization was successful.
return True
Loading

0 comments on commit 7236fce

Please sign in to comment.