Skip to content

Commit ed48705

Browse files
author
Ted Roberts
committed
Add audio output mode number entity
1 parent 90ce8f8 commit ed48705

4 files changed

Lines changed: 63 additions & 1 deletion

File tree

custom_components/novastar_h/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
}
2222
],
2323
"zeroconf": ["_novastar._tcp.local."],
24-
"version": "0.2.57"
24+
"version": "0.2.58"
2525
}

custom_components/novastar_h/number.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ async def async_setup_entry(
2525
[
2626
NovastarBrightnessNumber(entry, coordinator, device_info),
2727
NovastarAudioVolumeNumber(entry, coordinator, device_info),
28+
NovastarAudioOutputModeNumber(entry, coordinator, device_info),
2829
]
2930
)
3031

@@ -151,3 +152,58 @@ def native_value(self) -> float | None:
151152
async def async_set_native_value(self, value: float) -> None:
152153
"""Set audio volume value."""
153154
await self.coordinator.async_set_audio_volume(int(value))
155+
156+
157+
class NovastarAudioOutputModeNumber(CoordinatorEntity[NovastarCoordinator], NumberEntity):
158+
"""Number entity for audio output mode (audioOutputMode/outputChannelMode)."""
159+
160+
_attr_has_entity_name = True
161+
_attr_name = "Audio Output Mode"
162+
_attr_translation_key = "audio_output_mode"
163+
_attr_native_min_value = 0
164+
_attr_native_max_value = 255
165+
_attr_native_step = 1
166+
_attr_mode = NumberMode.BOX
167+
168+
def __init__(
169+
self,
170+
entry: ConfigEntry,
171+
coordinator: NovastarCoordinator,
172+
device_info: NovastarDeviceInfo,
173+
) -> None:
174+
"""Initialize the number entity."""
175+
super().__init__(coordinator)
176+
self._entry = entry
177+
self._device_info = device_info
178+
self._attr_unique_id = f"{entry.entry_id}_audio_output_mode"
179+
180+
@property
181+
def device_info(self):
182+
"""Return device info."""
183+
model = "H Series"
184+
if self._device_info.model_id:
185+
model = f"H Series (Model {self._device_info.model_id})"
186+
return {
187+
"identifiers": {(DOMAIN, self._entry.entry_id)},
188+
"manufacturer": "Novastar",
189+
"model": model,
190+
"name": self._entry.data.get(CONF_NAME, DEFAULT_NAME),
191+
"sw_version": self._device_info.firmware,
192+
"serial_number": self._device_info.serial,
193+
}
194+
195+
@property
196+
def available(self) -> bool:
197+
"""Return True if entity is available."""
198+
return self.coordinator.last_update_success
199+
200+
@property
201+
def native_value(self) -> float | None:
202+
"""Return current audio output mode."""
203+
if self.coordinator.data and self.coordinator.data.audio_output_id is not None:
204+
return float(self.coordinator.data.audio_output_id)
205+
return None
206+
207+
async def async_set_native_value(self, value: float) -> None:
208+
"""Set audio output mode value."""
209+
await self.coordinator.async_set_audio_output(int(value))

custom_components/novastar_h/strings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
},
140140
"audio_volume": {
141141
"name": "Audio Volume"
142+
},
143+
"audio_output_mode": {
144+
"name": "Audio Output Mode"
142145
}
143146
},
144147
"sensor": {

custom_components/novastar_h/translations/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
},
140140
"audio_volume": {
141141
"name": "Audio Volume"
142+
},
143+
"audio_output_mode": {
144+
"name": "Audio Output Mode"
142145
}
143146
},
144147
"sensor": {

0 commit comments

Comments
 (0)