Skip to content
Merged
Changes from 5 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
19 changes: 16 additions & 3 deletions homeassistant/components/reolink/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class ReolinkNumberEntityDescriptionMixin:
"""Mixin values for Reolink number entities."""

value: Callable[[Host, int | None], bool]
value: Callable[[Host, int | None], float]
get_min_value: Callable[[Host, int | None], float]
get_max_value: Callable[[Host, int | None], float]
method: Callable[[Host, int | None, float], Any]
Expand All @@ -50,7 +50,7 @@ class ReolinkNumberEntityDescription(
native_step=1,
get_min_value=lambda api, ch: api.zoom_range(ch)["zoom"]["pos"]["min"],
get_max_value=lambda api, ch: api.zoom_range(ch)["zoom"]["pos"]["max"],
supported=lambda api, ch: api.zoom_supported(ch),
supported=lambda api, ch: api.supported(ch, "zoom"),
value=lambda api, ch: api.get_zoom(ch),
method=lambda api, ch, value: api.set_zoom(ch, int(value)),
),
Expand All @@ -62,10 +62,22 @@ class ReolinkNumberEntityDescription(
native_step=1,
get_min_value=lambda api, ch: api.zoom_range(ch)["focus"]["pos"]["min"],
get_max_value=lambda api, ch: api.zoom_range(ch)["focus"]["pos"]["max"],
supported=lambda api, ch: api.zoom_supported(ch),
supported=lambda api, ch: api.supported(ch, "zoom"),
value=lambda api, ch: api.get_focus(ch),
method=lambda api, ch, value: api.set_zoom(ch, int(value)),
),
ReolinkNumberEntityDescription(
key="floodlight_brightness",
name="Floodlight brightness",
Comment thread
frenck marked this conversation as resolved.
Outdated
icon="mdi:spotlight-beam",
mode=NumberMode.SLIDER,
Comment thread
frenck marked this conversation as resolved.
Outdated
native_step=1,
get_min_value=lambda api, ch: 1,
get_max_value=lambda api, ch: 100,
Comment thread
starkillerOG marked this conversation as resolved.
Outdated
supported=lambda api, ch: api.supported(ch, "floodLight"),
value=lambda api, ch: api.whiteled_brightness(ch),
method=lambda api, ch, value: api.set_whiteled(ch, brightness=int(value)),
),
Comment on lines +70 to +81

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this number entity and the light entity for the floodlight?

ReolinkLightEntityDescription(
key="floodlight",
name="Floodlight",
icon="mdi:spotlight-beam",
supported_fn=lambda api, ch: api.supported(ch, "floodLight"),
is_on_fn=lambda api, ch: api.whiteled_state(ch),
turn_on_off_fn=lambda api, ch, value: api.set_whiteled(ch, state=value),
get_brightness_fn=lambda api, ch: api.whiteled_brightness(ch),
set_brightness_fn=lambda api, ch, value: api.set_whiteled(ch, brightness=value),
),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See discussion above: #87932 (review)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read up on the comment history in the PR.

Please add a code comment explaining the situation so we don't need to wonder what's going on when reading the code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
CC @starkillerOG

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a code comment and some extra documentation because this is indeed not clear enough, just a moment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation PR is here: home-assistant/home-assistant.io#26469

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code comment PR is here: #89234

)


Expand Down Expand Up @@ -120,3 +132,4 @@ def native_value(self) -> float:
async def async_set_native_value(self, value: float) -> None:
"""Update the current value."""
await self.entity_description.method(self._host.api, self._channel, value)
self.async_write_ha_state()