Skip to content
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
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ homeassistant.components.tcp.*
homeassistant.components.technove.*
homeassistant.components.tedee.*
homeassistant.components.telegram_bot.*
homeassistant.components.teslemetry.*
homeassistant.components.text.*
homeassistant.components.thethingsnetwork.*
homeassistant.components.threshold.*
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/airobot/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ async def async_set_native_value(self, value: float) -> None:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key="set_value_failed",
translation_placeholders={"error": str(err)},
) from err
else:
await self.coordinator.async_request_refresh()
2 changes: 1 addition & 1 deletion homeassistant/components/airobot/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"message": "Failed to set temperature to {temperature}."
},
"set_value_failed": {
"message": "Failed to set value: {error}"
"message": "Failed to set value."
},
"switch_turn_off_failed": {
"message": "Failed to turn off {switch}."
Expand Down
12 changes: 5 additions & 7 deletions homeassistant/components/anthropic/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ def _convert_content(
# If there is only one text block, simplify the content to a string
messages[-1]["content"] = messages[-1]["content"][0]["text"]
else:
# Note: We don't pass SystemContent here as its passed to the API as the prompt
raise TypeError(f"Unexpected content type: {type(content)}")
# Note: We don't pass SystemContent here as it's passed to the API as the prompt
raise HomeAssistantError("Unexpected content type in chat log")

return messages, container_id

Expand Down Expand Up @@ -442,8 +442,8 @@ async def _transform_stream( # noqa: C901 - This is complex, but better to have
Each message could contain multiple blocks of the same type.
"""
if stream is None:
raise TypeError("Expected a stream of messages")
if stream is None or not hasattr(stream, "__aiter__"):
raise HomeAssistantError("Expected a stream of messages")

current_tool_block: ToolUseBlockParam | ServerToolUseBlockParam | None = None
current_tool_args: str
Expand All @@ -456,8 +456,6 @@ async def _transform_stream( # noqa: C901 - This is complex, but better to have
LOGGER.debug("Received response: %s", response)

if isinstance(response, RawMessageStartEvent):
if response.message.role != "assistant":
raise ValueError("Unexpected message role")
input_usage = response.message.usage
first_block = True
elif isinstance(response, RawContentBlockStartEvent):
Expand Down Expand Up @@ -666,7 +664,7 @@ async def _async_handle_chat_log(

system = chat_log.content[0]
if not isinstance(system, conversation.SystemContent):
raise TypeError("First message must be a system message")
raise HomeAssistantError("First message must be a system message")

# System prompt with caching enabled
system_prompt: list[TextBlockParam] = [
Expand Down
5 changes: 1 addition & 4 deletions homeassistant/components/anthropic/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ rules:
test-before-setup: done
unique-config-entry: done
# Silver
action-exceptions:
status: todo
comment: |
Reevaluate exceptions for entity services.
action-exceptions: done
config-entry-unloading: done
docs-configuration-parameters: done
docs-installation-parameters: done
Expand Down
17 changes: 1 addition & 16 deletions homeassistant/components/aquostv/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class SharpAquosTVDevice(MediaPlayerEntity):
| MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.PLAY
)
_attr_volume_step = 2 / 60

def __init__(
self, name: str, remote: sharp_aquos_rc.TV, power_on_enabled: bool = False
Expand Down Expand Up @@ -161,22 +162,6 @@ def turn_off(self) -> None:
"""Turn off tvplayer."""
self._remote.power(0)

@_retry
def volume_up(self) -> None:
"""Volume up the media player."""
if self.volume_level is None:
_LOGGER.debug("Unknown volume in volume_up")
return
self._remote.volume(int(self.volume_level * 60) + 2)

@_retry
def volume_down(self) -> None:
"""Volume down media player."""
if self.volume_level is None:
_LOGGER.debug("Unknown volume in volume_down")
return
self._remote.volume(int(self.volume_level * 60) - 2)

@_retry
def set_volume_level(self, volume: float) -> None:
"""Set Volume media player."""
Expand Down
19 changes: 1 addition & 18 deletions homeassistant/components/bluesound/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class BluesoundPlayer(CoordinatorEntity[BluesoundCoordinator], MediaPlayerEntity
_attr_media_content_type = MediaType.MUSIC
_attr_has_entity_name = True
_attr_name = None
_attr_volume_step = 0.01

def __init__(
self,
Expand Down Expand Up @@ -688,24 +689,6 @@ async def async_play_media(

await self._player.play_url(url)

async def async_volume_up(self) -> None:
"""Volume up the media player."""
if self.volume_level is None:
return

new_volume = self.volume_level + 0.01
new_volume = min(1, new_volume)
await self.async_set_volume_level(new_volume)

async def async_volume_down(self) -> None:
"""Volume down the media player."""
if self.volume_level is None:
return

new_volume = self.volume_level - 0.01
new_volume = max(0, new_volume)
await self.async_set_volume_level(new_volume)

async def async_set_volume_level(self, volume: float) -> None:
"""Send volume_up command to media player."""
volume = int(round(volume * 100))
Expand Down
12 changes: 0 additions & 12 deletions homeassistant/components/demo/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,6 @@ def mute_volume(self, mute: bool) -> None:
self._attr_is_volume_muted = mute
self.schedule_update_ha_state()

def volume_up(self) -> None:
"""Increase volume."""
assert self.volume_level is not None
self._attr_volume_level = min(1.0, self.volume_level + 0.1)
self.schedule_update_ha_state()

def volume_down(self) -> None:
"""Decrease volume."""
assert self.volume_level is not None
self._attr_volume_level = max(0.0, self.volume_level - 0.1)
self.schedule_update_ha_state()

def set_volume_level(self, volume: float) -> None:
"""Set the volume level, range 0..1."""
self._attr_volume_level = volume
Expand Down
14 changes: 2 additions & 12 deletions homeassistant/components/frontier_silicon/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ async def async_update(self) -> None:
# If call to get_volume fails set to 0 and try again next time.
if not self._max_volume:
self._max_volume = int(await afsapi.get_volume_steps() or 1) - 1
if self._max_volume:
self._attr_volume_step = 1 / self._max_volume

if self._attr_state != MediaPlayerState.OFF:
info_name = await afsapi.get_play_name()
Expand Down Expand Up @@ -239,18 +241,6 @@ async def async_mute_volume(self, mute: bool) -> None:
await self.fs_device.set_mute(mute)

# volume
async def async_volume_up(self) -> None:
"""Send volume up command."""
volume = await self.fs_device.get_volume()
volume = int(volume or 0) + 1
await self.fs_device.set_volume(min(volume, self._max_volume or 1))

async def async_volume_down(self) -> None:
"""Send volume down command."""
volume = await self.fs_device.get_volume()
volume = int(volume or 0) - 1
await self.fs_device.set_volume(max(volume, 0))

async def async_set_volume_level(self, volume: float) -> None:
"""Set volume command."""
if self._max_volume: # Can't do anything sensible if not set
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/govee_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,5 @@
"documentation": "https://www.home-assistant.io/integrations/govee_ble",
"integration_type": "device",
"iot_class": "local_push",
"requirements": ["govee-ble==0.44.0"]
"requirements": ["govee-ble==1.2.0"]
}
15 changes: 1 addition & 14 deletions homeassistant/components/monoprice/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class MonopriceZone(MediaPlayerEntity):
)
_attr_has_entity_name = True
_attr_name = None
_attr_volume_step = 1 / MAX_VOLUME

def __init__(self, monoprice, sources, namespace, zone_id):
"""Initialize new zone."""
Expand Down Expand Up @@ -211,17 +212,3 @@ def mute_volume(self, mute: bool) -> None:
def set_volume_level(self, volume: float) -> None:
"""Set volume level, range 0..1."""
self._monoprice.set_volume(self._zone_id, round(volume * MAX_VOLUME))

def volume_up(self) -> None:
"""Volume up the media player."""
if self.volume_level is None:
return
volume = round(self.volume_level * MAX_VOLUME)
self._monoprice.set_volume(self._zone_id, min(volume + 1, MAX_VOLUME))

def volume_down(self) -> None:
"""Volume down media player."""
if self.volume_level is None:
return
volume = round(self.volume_level * MAX_VOLUME)
self._monoprice.set_volume(self._zone_id, max(volume - 1, 0))
19 changes: 1 addition & 18 deletions homeassistant/components/mpd/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class MpdDevice(MediaPlayerEntity):
_attr_media_content_type = MediaType.MUSIC
_attr_has_entity_name = True
_attr_name = None
_attr_volume_step = 0.05

def __init__(
self, server: str, port: int, password: str | None, unique_id: str
Expand Down Expand Up @@ -393,24 +394,6 @@ async def async_set_volume_level(self, volume: float) -> None:
if "volume" in self._status:
await self._client.setvol(int(volume * 100))

async def async_volume_up(self) -> None:
"""Service to send the MPD the command for volume up."""
async with self.connection():
if "volume" in self._status:
current_volume = int(self._status["volume"])

if current_volume <= 100:
self._client.setvol(current_volume + 5)

async def async_volume_down(self) -> None:
"""Service to send the MPD the command for volume down."""
async with self.connection():
if "volume" in self._status:
current_volume = int(self._status["volume"])

if current_volume >= 0:
await self._client.setvol(current_volume - 5)

async def async_media_play(self) -> None:
"""Service to send the MPD the command for play/pause."""
async with self.connection():
Expand Down
12 changes: 3 additions & 9 deletions homeassistant/components/nad/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ def __init__(self, config):
self._nad_receiver = NADReceiverTCP(config.get(CONF_HOST))
self._min_vol = (config[CONF_MIN_VOLUME] + 90) * 2 # from dB to nad vol (0-200)
self._max_vol = (config[CONF_MAX_VOLUME] + 90) * 2 # from dB to nad vol (0-200)
self._volume_step = config[CONF_VOLUME_STEP]
self._nad_volume = None
vol_range = self._max_vol - self._min_vol
if vol_range:
self._attr_volume_step = 2 * config[CONF_VOLUME_STEP] / vol_range
self._source_list = self._nad_receiver.available_sources()

def turn_off(self) -> None:
Expand All @@ -210,14 +212,6 @@ def turn_on(self) -> None:
"""Turn the media player on."""
self._nad_receiver.power_on()

def volume_up(self) -> None:
"""Step volume up in the configured increments."""
self._nad_receiver.set_volume(self._nad_volume + 2 * self._volume_step)

def volume_down(self) -> None:
"""Step volume down in the configured increments."""
self._nad_receiver.set_volume(self._nad_volume - 2 * self._volume_step)

def set_volume_level(self, volume: float) -> None:
"""Set volume level, range 0..1."""
nad_volume_to_set = int(
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/shelly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from .services import async_setup_services
from .utils import (
async_create_issue_unsupported_firmware,
async_migrate_rpc_sensor_description_unique_ids,
async_migrate_rpc_virtual_components_unique_ids,
get_coap_context,
get_device_entry_gen,
Expand Down Expand Up @@ -296,6 +297,12 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ShellyConfigEntry)
runtime_data = entry.runtime_data
runtime_data.platforms = RPC_SLEEPING_PLATFORMS

await er.async_migrate_entries(
hass,
entry.entry_id,
async_migrate_rpc_sensor_description_unique_ids,
)

if sleep_period == 0:
# Not a sleeping device, finish setup
LOGGER.debug("Setting up online RPC device %s", entry.title)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/shelly/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ def __init__(
entity_category=EntityCategory.DIAGNOSTIC,
use_polling_coordinator=True,
),
"temperature_0": RpcSensorDescription(
"temperature_tc": RpcSensorDescription(
key="temperature",
sub_key="tC",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
Expand Down Expand Up @@ -1249,7 +1249,7 @@ def __init__(
entity_category=EntityCategory.DIAGNOSTIC,
use_polling_coordinator=True,
),
"humidity_0": RpcSensorDescription(
"humidity_rh": RpcSensorDescription(
key="humidity",
sub_key="rh",
native_unit_of_measurement=PERCENTAGE,
Expand Down
24 changes: 24 additions & 0 deletions homeassistant/components/shelly/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,30 @@ def format_ble_addr(ble_addr: str) -> str:
return ble_addr.replace(":", "").upper()


@callback
def async_migrate_rpc_sensor_description_unique_ids(
entity_entry: er.RegistryEntry,
) -> dict[str, Any] | None:
"""Migrate RPC sensor unique_ids after sensor description key rename."""
unique_id_map = {
"-temperature_0": "-temperature_tc",
"-humidity_0": "-humidity_rh",
}

for old_suffix, new_suffix in unique_id_map.items():
if entity_entry.unique_id.endswith(old_suffix):
new_unique_id = entity_entry.unique_id.removesuffix(old_suffix) + new_suffix
LOGGER.debug(
"Migrating unique_id for %s entity from [%s] to [%s]",
entity_entry.entity_id,
entity_entry.unique_id,
new_unique_id,
)
return {"new_unique_id": new_unique_id}

return None


@callback
def async_migrate_rpc_virtual_components_unique_ids(
config: dict[str, Any], entity_entry: er.RegistryEntry
Expand Down
Loading
Loading