Skip to content

Commit

Permalink
feat: Spoolman version in device info closes #25
Browse files Browse the repository at this point in the history
refactor: Wrapped Spoolman api in a wrapper
  • Loading branch information
Disane87 committed Oct 4, 2023
1 parent a18dffb commit f3f72eb
Show file tree
Hide file tree
Showing 8 changed files with 2,321 additions and 80 deletions.
16 changes: 16 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"recommendations": [
"ms-python.black-formatter",
"vadimcn.vscode-lldb",
"vivaxy.vscode-conventional-commits",
"ryanluker.vscode-coverage-gutters",
"serayuzgur.crates",
"dbaeumer.vscode-eslint",
"tamasfe.even-better-toml",
"github.vscode-pull-request-github",
"eamodio.gitlens",
"ms-python.vscode-pylance",
"ms-python.python",
"charliermarsh.ruff"
]
}
35 changes: 19 additions & 16 deletions custom_components/spoolman/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""Spoolman home assistant integration."""
import logging
import aiohttp

from homeassistant.const import Platform, CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.components.sensor import PLATFORM_SCHEMA
import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME, Platform
from homeassistant.core import HomeAssistant

from .const import DOMAIN, CONF_URL, DEFAULT_NAME
from .const import CONF_URL, DEFAULT_NAME, DOMAIN, SPOOLMAN_API_WRAPPER
from .coordinator import SpoolManCoordinator

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -40,6 +39,7 @@ async def async_setup_entry(hass: HomeAssistant, entry):
"""Set up the Spoolman component from a config entry."""
_LOGGER.debug("__init__.async_setup_entry")
# session = async_create_clientsession(hass)

coordinator = SpoolManCoordinator(hass, entry)
await coordinator.async_refresh()
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
Expand All @@ -58,14 +58,17 @@ async def async_unload_entry(hass: HomeAssistant, entry):
async def async_get_data(hass: HomeAssistant):
"""Get the latest data from the Spoolman API."""
_LOGGER.debug("__init__.async_get_data")
url = hass.data[DOMAIN][CONF_URL]

async with aiohttp.ClientSession() as session:
try:
headers = {}

async with session.get(url, headers=headers) as response:
data = await response.json()
return data
except Exception as ex:
_LOGGER.error("Error fetching data from Spoolman API: %s", ex)
# url = hass.data[DOMAIN][CONF_URL]
return await hass.data[DOMAIN][SPOOLMAN_API_WRAPPER].get_spool(
{"allow_archived": False}
)

# async with aiohttp.ClientSession() as session:
# try:
# headers = {}

# async with session.get(url, headers=headers) as response:
# data = await response.json()
# return data
# except Exception as ex:
# _LOGGER.error("Error fetching data from Spoolman API: %s", ex)
Loading

0 comments on commit f3f72eb

Please sign in to comment.