Skip to content

Commit

Permalink
fixed config loading into devcontainer, updating images, add graph im…
Browse files Browse the repository at this point in the history
…age, unique_id for images
  • Loading branch information
tcarwash committed Apr 13, 2024
1 parent 7f49b2d commit c788e15
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
7 changes: 5 additions & 2 deletions custom_components/noaa_space_weather/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from .const import ATTRIBUTION
from .const import DOMAIN

class NoaaSpaceWeatherImageEntity(ImageEntity):

class NoaaSpaceWeatherImageEntity(CoordinatorEntity, ImageEntity):
"""NOAA Space Weather Image Entity"""

def __init__(self, coordinator, config_entry):
super().__init__(coordinator.hass, config_entry)
super().__init__(coordinator, config_entry)
ImageEntity.__init__(self, coordinator.hass)
self.coordinator = coordinator
self.config_entry = config_entry

Expand All @@ -23,6 +25,7 @@ def extra_state_attributes(self):
"integration": DOMAIN,
}


class NoaaSpaceWeatherEntity(CoordinatorEntity):
"""NOAA Space Weather Entity"""

Expand Down
42 changes: 37 additions & 5 deletions custom_components/noaa_space_weather/image.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
"""Camera platform for NOAA Space Weather."""

from .const import DOMAIN
from .const import ATTRIBUTION
import logging
from .entity import NoaaSpaceWeatherImageEntity
from homeassistant.components.image import ImageEntity
from homeassistant.core import callback
from datetime import datetime


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


async def async_setup_entry(hass, entry, async_add_devices):
"""Setup camera platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
imagemap = [
{
"name": "ace_solar_wind_3h",
"image_url": "https://services.swpc.noaa.gov/images/ace-mag-swepam-2-hour.gif",
"device_class": "graph",
},
{
"name": "aurora_forecast_north",
"image_url": "https://services.swpc.noaa.gov/images/animations/ovation/north/latest.jpg",
Expand All @@ -35,15 +45,37 @@ class NoaaSpaceWeatherImage(NoaaSpaceWeatherImageEntity):
"""noaa_space_weather Image class."""

def __init__(self, coordinator, entry, image):
self.image = image
self.image_data = image
self.entry = entry
self.coordinator = coordinator
super().__init__(coordinator, entry)

@property
def unique_id(self):
return f"swpc {self.image_data['name']}"

@property
def name(self):
return self.image.get("name")
return self.image_data.get("name")

@property
def state(self):
if self._cached_image:
return "available"
else:
return "available"

@property
def image_url(self):
return self.image.get("image_url")
return self.image_data.get("image_url")

@property
def device_class(self):
"""Return the device class of the image."""
return self.image_data.get("device_class", "noaa_space_weather__image")

@callback
def _handle_coordinator_update(self):
self.image_last_updated = datetime.now()
self._cached_image = None
self.async_write_ha_state()
2 changes: 2 additions & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ scripts/install/pip_packages "pip"
scripts/install/pip_packages setuptools wheel
scripts/install/core
rm -rf /workspaces/home-assistant_noaa-space-weather/config
mkdir /workspaces/home-assistant_noaa-space-weather/config
ln -s /workspaces/home-assistant_noaa-space-weather/.devcontainer/configuration.yaml /workspaces/home-assistant_noaa-space-weather/config/configuration.yaml
hass --config $(pwd)/config --script ensure_config
ln -s /workspaces/home-assistant_noaa-space-weather/custom_components /workspaces/home-assistant_noaa-space-weather/config/custom_components
scripts/install/dev

0 comments on commit c788e15

Please sign in to comment.