Add downloading of pattern

This commit is contained in:
Evan Fiordeliso 2023-01-29 20:57:59 -05:00
parent 8397bc3ccd
commit 3ebe6a2ccf
5 changed files with 76 additions and 55 deletions

View File

@ -1,58 +1,12 @@
from typing import Any from flickerstrip_py import Flickerstrip
import flickerstrip_py as flstrp
from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import Entity
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
LightEntity,
)
from .const import (
DEFAULT_PORT,
)
class Flickerstrip(LightEntity): class FlickerstripEntity(Entity):
"""Flickerstrip class.""" """Base flickerstrip entity."""
def __init__( def __init__(self, host: str, port: int = 80):
self, self.host: str = host
hass: HomeAssistant, self.port: int = port
host: str, self.strip: Flickerstrip = Flickerstrip(host, port)
port: int = DEFAULT_PORT,
):
self.hass = hass
self.host = host
self.port = port
self._flickerstrip = flstrp.Flickerstrip(host)
@property
def name(self) -> str:
"""Return the display name of this light."""
return self._name
@property
def brightness(self):
"""Return the brightness of the light."""
return self._flickerstrip.status.brightness
@property
def is_on(self) -> bool | None:
"""Return true if light is on."""
return self._flickerstrip.status.power
def turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on."""
brightness = kwargs.get(ATTR_BRIGHTNESS, 100)
self._flickerstrip.set_brightness(brightness)
self._flickerstrip.power_on()
def turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""
self._flickerstrip.power_off()
def update(self) -> None:
"""Fetch new state data for this light.
This is the only method that should fetch new data for Home Assistant.
"""
self._flickerstrip.force_update()

View File

@ -0,0 +1,65 @@
from typing import Any
from homeassistant.core import HomeAssistant
from homeassistant.components.light import (
LightEntity,
ATTR_BRIGHTNESS,
ColorMode
)
from .common import FlickerstripEntity
from .const import (
DEFAULT_PORT,
)
class FlickerstripLight(FlickerstripEntity, LightEntity):
"""Flickerstrip class."""
def __init__(
self,
hass: HomeAssistant,
host: str,
port: int = DEFAULT_PORT,
):
super().__init__(host, port)
self.hass = hass
@property
def color_mode():
return ColorMode.RGB
@property
def supported_color_mode():
return [ColorMode.RGB]
@property
def name(self) -> str:
"""Return the display name of this light."""
return self.strip.status.name if len(self.strip.status.name) > 0 else "Flickerstrip"
@property
def brightness(self):
"""Return the brightness of the light."""
return self.strip.status.brightness
@property
def is_on(self) -> bool | None:
"""Return true if light is on."""
return self.strip.status.power
async def async_turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on."""
brightness = kwargs.get(ATTR_BRIGHTNESS, 100)
await self.strip.set_brightness(brightness)
await self.strip.power_on()
async def async_turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""
await self.strip.power_off()
async def async_update(self) -> None:
"""Fetch new state data for this light.
This is the only method that should fetch new data for Home Assistant.
"""
await self.strip.force_update()

View File

@ -14,7 +14,7 @@
} }
], ],
"requirements": [ "requirements": [
"git+https://git.fifitido.net/lib/flickerstrip-py@d808ca8ac8#egg=flickerstrip-py" "flickerstrip-py @ git+https://git.fifitido.net/lib/flickerstrip-py"
], ],
"version": "1.0.0" "version": "1.0.0"
} }

2
requirements_dev.txt Normal file
View File

@ -0,0 +1,2 @@
homeassistant==2023.1.7
flickerstrip-py @ git+https://git.fifitido.net/lib/flickerstrip-py