Skip to content

Commit

Permalink
Add display
Browse files Browse the repository at this point in the history
  • Loading branch information
theneweinstein committed Jun 17, 2024
1 parent 98a4f9c commit a63a727
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 3 deletions.
9 changes: 9 additions & 0 deletions custom_components/somneo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,12 @@ async def async_set_sunset(
)
)
await self.async_request_refresh()

async def async_set_display(
self, state: bool | None = None, brightness: int | None = None):
"""Adjust the display."""
async with self.state_lock:
await self.hass.async_add_executor_job(
ft.partial(self.somneo.set_display, state=state, brightness=brightness)
)
await self.async_request_refresh()
6 changes: 6 additions & 0 deletions custom_components/somneo/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
},
"sunset_volume": {
"default": "mdi:volume-high"
},
"display_brightness": {
"default": "mdi:brightness-5"
}
},
"select": {
Expand Down Expand Up @@ -116,6 +119,9 @@
"default": "mdi:volume-high"
}
}
},
"display_on": {
"default": "mdi:monitor"
}
},
"text":{
Expand Down
4 changes: 2 additions & 2 deletions custom_components/somneo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
"somneo"
],
"requirements": [
"pysomneo==4.2.0"
"pysomneo==4.2.1"
],
"ssdp": [
{
"nt": "urn:philips-com:device:DiProduct:1",
"modelName": "Wake-up Light"
}
],
"version": "2024.6.0"
"version": "2024.6.1"
}
27 changes: 26 additions & 1 deletion custom_components/somneo/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ async def async_setup_entry(
SomneoSunsetVolume(coordinator, unique_id, name, device_info, "sunset_volume")
]

display = [SomneoDisplayBrightness(coordinator, unique_id, name, device_info, "display_brightness")]

async_add_entities(alarms, update_before_add=True)
async_add_entities(snooze, update_before_add=True)
async_add_entities(sunset, update_before_add=True)
async_add_entities(display, update_before_add=True)


class SomneoPowerWake(SomneoEntity, NumberEntity):
Expand Down Expand Up @@ -158,4 +161,26 @@ def _handle_coordinator_update(self) -> None:

async def async_set_native_value(self, value: float) -> None:
"""Called when user adjust snooze time in the UI"""
await self.coordinator.async_set_sunset(volume = int(value))
await self.coordinator.async_set_sunset(volume = int(value))


class SomneoDisplayBrightness(SomneoEntity, NumberEntity):
"""Represenation of the Sunset volume."""

_attr_should_poll = True
_attr_available = True
_attr_assumed_state = False
_attr_translation_key = "display_brightness"
_attr_native_min_value = 1
_attr_native_max_value = 6
_attr_native_step = 1
_attr_has_entity_name = True

@callback
def _handle_coordinator_update(self) -> None:
self._attr_native_value = self.coordinator.data["display_brightness"]
self.async_write_ha_state()

async def async_set_native_value(self, value: float) -> None:
"""Called when user adjust snooze time in the UI"""
await self.coordinator.async_set_display(brightness = int(value))
22 changes: 22 additions & 0 deletions custom_components/somneo/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ async def async_setup_entry(

sunset = [SomneoSunsetToggle(coordinator, unique_id, name, device_info, "sunset")]

display = [SomneoDisplayToggle(coordinator, unique_id, name, device_info, 'display_on')]

async_add_entities(alarms, update_before_add=True)
async_add_entities(pwrwk, update_before_add=True)
async_add_entities(sunset, update_before_add=True)
async_add_entities(display, update_before_add=True)

platform = entity_platform.async_get_current_platform()

Expand Down Expand Up @@ -202,3 +205,22 @@ async def async_turn_on(self, **kwargs: Any):
async def async_turn_off(self, **kwargs: Any):
"""Turn off the switch."""
await self.coordinator.async_toggle_sunset(False)

class SomneoDisplayToggle(SomneoEntity, SwitchEntity):
"""Representation of a display always on switch."""

_attr_should_poll = True
_attr_translation_key = 'display_on'

@callback
def _handle_coordinator_update(self) -> None:
self._attr_is_on = self.coordinator.data["display_always_on"]
self.async_write_ha_state()

async def async_turn_on(self, **kwargs: Any):
"""Turn on the switch."""
await self.coordinator.async_set_display(state=True)

async def async_turn_off(self, **kwargs: Any):
"""Turn off the switch."""
await self.coordinator.async_set_display(state=False)
6 changes: 6 additions & 0 deletions custom_components/somneo/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
"name": "Volume"
}
}
},
"display_on": {
"name": "Display always on"
}
},
"number": {
Expand All @@ -180,6 +183,9 @@
},
"sunset_volume": {
"name": "Sunset volume"
},
"display_brightness": {
"name": "Display brightness"
}
},
"text": {
Expand Down
6 changes: 6 additions & 0 deletions custom_components/somneo/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
"name": "Volume"
}
}
},
"display_on": {
"name": "Scherm altijd aan"
}
},
"number": {
Expand All @@ -180,6 +183,9 @@
},
"sunset_volume": {
"name": "Zonsondergang volume"
},
"display_brightness": {
"name": "Scherm helderheid"
}
},
"text": {
Expand Down

0 comments on commit a63a727

Please sign in to comment.