Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: number entity units and conversion to/from Exoy ONE #2

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Lint"

on:
push:
branches:
- "main"
pull_request:
branches:
- "main"

jobs:
ruff:
name: "Ruff"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout the repository"
uses: "actions/checkout@v4.1.7"

- name: "Set up Python"
uses: actions/setup-python@v5.1.1
with:
python-version: "3.12"
cache: "pip"

- name: "Install requirements"
run: python3 -m pip install -r requirements.txt

- name: "Lint"
run: python3 -m ruff check .

- name: "Format"
run: python3 -m ruff format . --check
33 changes: 25 additions & 8 deletions custom_components/exoy_one/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(self, hass: HomeAssistant) -> None:
logger=LOGGER,
name=DOMAIN,
update_interval=timedelta(seconds=3),
always_update=False,
)
self.mp = mode_packs

Expand All @@ -56,29 +55,44 @@ async def _async_update_data(self) -> Any:
def async_is_on(self, key: str) -> bool:
"""Return True if the key is on."""
if key == "musicSync":
return True if self.state.forceMusicSync is True else self.state.musicSync
return True if self.state.forceMusicSync else self.state.musicSync

return getattr(self.state, key)

def async_is_available(self, key: str) -> bool:
"""Return true if the key is available."""
return not (
(self.state.sceneGeneration is True and key in {"musicSync", "autoChange"})
or (self.state.forceMusicSync is True and key == "musicSync")
)
if key == "musicSync":
return not self.state.forceMusicSync or self.state.sceneGeneration

if key == "autoChange":
return not self.state.sceneGeneration

def async_get_sensor_value(self, key: str) -> str | None:
return True

def async_get_sensor_value(self, key: str) -> str | int | None:
"""Return the value of the sensor."""
if key == "currentModpack":
return self.mp.get_pack_name_from_index(self.state.currentModpack)
if key == "modeIndex":
return self.mp.get_effect_name_from_index(
self.state.currentModpack, self.state.modeIndex
)
if key == "speed":
return int(self.state.speed / 255 * 100)

if key == "shutdownTimer":
return int(self.state.shutdownTimer / 60)

if key == "cycleSpeed":
return self.state.cycleSpeed

return None

async def async_set_value(self, key: str, value: float) -> None:
"""Set a new value for the specified key."""
if key == "speed":
value = int(value / 100 * 255)

method = getattr(self.exoyone, get_method_for_attribute(key))
await method(value)

Expand All @@ -89,8 +103,11 @@ async def async_turn_on(self, key: str) -> None:

async def async_turn_off(self, key: str) -> None:
"""Turn off the switch."""
if key == "shutdownTimer":
return await self.exoyone.set_shutdown_timer(0)

method = getattr(self.exoyone, get_method_for_attribute(key))
await method("off")
return await method("off")

def async_current_option(self, key: str) -> str:
"""Return the current selected option."""
Expand Down
11 changes: 5 additions & 6 deletions custom_components/exoy_one/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
LightEntityFeature,
)

from .const import LOGGER
from .entity import ExoyOneEntity

if TYPE_CHECKING:
Expand Down Expand Up @@ -90,11 +89,11 @@ def hs_color(self) -> tuple[float, float]:
@property
def color_mode(self) -> ColorMode:
"""Return current color mode."""
if self.coordinator.state.lockColorWheel is True:
LOGGER.debug("Color wheel is locked, returning BRIGHTNESS")
return ColorMode.BRIGHTNESS
LOGGER.debug("Color wheel is unlocked, returning HS")
return ColorMode.HS
return (
ColorMode.BRIGHTNESS
if self.coordinator.state.lockColorWheel is True
else ColorMode.HS
)

@property
def effect(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/exoy_one/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"iot_class": "local_polling",
"issue_tracker": "/~https://github.com/Djelibeybi/hass-ExoyONE/issues",
"loggers": ["exoyone"],
"requirements": ["pyExoyOne==0.1.2"],
"version": "2024.8.0",
"requirements": ["pyExoyOne==0.1.3"],
"version": "2024.8.2",
"zeroconf": [
{"type": "_http._tcp.local.", "name": "exoyone*"}
]
Expand Down
16 changes: 15 additions & 1 deletion custom_components/exoy_one/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
icon="mdi:play-speed",
entity_category=EntityCategory.CONFIG,
device_class=NumberDeviceClass.SPEED,
native_unit_of_measurement="%",
native_max_value=100,
native_min_value=0,
native_step=1,
),
NumberEntityDescription(
key="cycleSpeed",
Expand All @@ -35,14 +39,19 @@
entity_category=EntityCategory.CONFIG,
device_class=NumberDeviceClass.DURATION,
native_unit_of_measurement="s",
native_max_value=300,
mode="box",
),
NumberEntityDescription(
key="shutdownTimer",
name="Shutdown timer",
icon="mdi:alarm",
entity_category=EntityCategory.CONFIG,
device_class=NumberDeviceClass.DURATION,
native_unit_of_measurement="s",
native_unit_of_measurement="min",
native_max_value=480,
native_min_value=0,
mode="slider",
),
)

Expand Down Expand Up @@ -83,6 +92,11 @@ def __init__(
f"number.{self.coordinator.exoyone.state.mdnsName}_{entity_description.key}"
)

@property
def native_value(self) -> float:
"""Return the value of the entity."""
return self.coordinator.async_get_sensor_value(self.entity_description.key)

async def async_set_native_value(self, value: float) -> None:
"""Update the current value."""
return await self.coordinator.async_set_value(
Expand Down
File renamed without changes.