Skip to main content

· One min read

For Home Assistant Core 2022.9, we have deprecated AutomationActionType, AutomationTriggerInfo, and AutomationTriggerData from homeassistant/components/automation/__init__.py. They are being replaced by TriggerActionType, TriggerInfo, and TriggerData from homeassistant/helpers/trigger.py.

OldNew
AutomationActionTypeTriggerActionType
AutomationTriggerInfoTriggerInfo
AutomationTriggerDataTriggerData

Furthermore, we recommend updating the automation_info parameter name for the async_attach_trigger function to trigger_info.

· One min read

For Home Assistant Core 2022.9 we have changed the PassiveBluetoothProcessorCoordinator and PassiveBluetoothDataProcessor bluetooth API's to make PassiveBluetoothProcessorCoordinator responsible for parsing. The coordinator then pushes parsed data to PassiveBluetoothDataProcessor instances.

PassiveBluetoothProcessorCoordinator now takes a mandatory update_method callback that receives bluetooth advertisements (in the form of BluetoothServiceInfoBleak) and returns the data that should be handed off to any subscribed PassiveBluetoothDataProcessor:

def my_parser(service_info: BluetoothServiceInfoBleak) -> MyDataClass:
...

return MyDataClass(
a=some_parsed_data,
b=some_other_parsed_data,
)


coordinator = PassiveBluetoothProcessorCoordinator(
hass,
_LOGGER,
address=address,
mode=BluetoothScanningMode.PASSIVE,
update_method=my_parser,
)

PassiveBluetoothDataProcessor still takes an update_method, but instead of a BluetoothServiceInfoBleak, it now receives the data returned from PassiveBluetoothProcessorCoordinator's update_method. It should still return a PassiveBluetoothDataUpdate as before:

def sensor_update_to_bluetooth_data_update(
sensor_update: MyDataClass,
) -> PassiveBluetoothDataUpdate:
"""Convert a sensor update to a bluetooth data update."""
...
return PassiveBluetoothDataUpdate( ... )

processor = PassiveBluetoothDataProcessor(sensor_update_to_bluetooth_data_update)

All the built-in integrations have already been converted, so take a look at them for more examples.

This change will help integrations that need to start parsing data before loading a platform (for example, the list of platforms to load depend on data from the advertisements) or changes where a single advertisement drives multiple platforms (you won't have to parse the broadcast twice).

· One min read

For Home Assistant Core 2022.9, we have deprecated the device_tracker SOURCE_TYPE_* constants. Use the new SourceType enum instead.

Deprecated constants:

  • SOURCE_TYPE_GPS
  • SOURCE_TYPE_ROUTER
  • SOURCE_TYPE_BLUETOOTH
  • SOURCE_TYPE_BLUETOOTH_LE

· 3 min read

We are working on improving and standardizing our entity naming. This will allow us to show, in the UI, entities in the right context in the future while removing some error-prone magic mangling of entity names from the code base.

The short story is:

  • Devices have their name as they have today, for example, "Dishwasher".
  • Entities will have their own name (without device, area). Or, they may optionally set the name to None (in that case they inherit the device name).
  • Device, Area, and Entity names all start with a capital letter, the rest of the words are lower case (unless it's a word that represents a brand/name/abbreviation of course).
  • Every entity which has been migrated to follow these rules should set the has_entity_name property to True.

During the migration period, we use the has_entity_name property to create "backward compatible" friendly names. In the future, we can show deprecation warnings for entities that don't set this property, and later, remove it entirely.

The frontend is going to be adjusted for this. It will be able to show the entities/devices in various ways, what suits the context the most.

Example

This illustrates how devices and entities should be named according to the new recommendations (type: entity name / state object's friendly_name / entity_id). Developers only need to set device name and entity name, the friendly_name and entity_id are automatically generated.

  • Device: Dishwasher
    • Switch: None / Dishwasher / switch.dishwasher
    • Sensor: Power usage / Dishwasher Power usage / sensor.dishwasher_power_usage
  • Device: Laundry machine
    • Switch: None / Laundry machine / switch.laundry_machine
    • Sensor: Power usage / Laundry machine Power usage / sensor.laundry_machine_power_usage

Background

Home Assistant models the home of a user into three levels:

  • Area (eg. Living Room)
  • Device (eg. Switch)
  • Entity (eg. Power usage)

Entities in Home Assistant are the data points provided by a device and can represent specific controls (a switch of the device, a light of the device).

Because Home Assistant used to only have entities in the first many years of its existence, a lot of functionality is based around entities in Home Assistant, the main one being the UI.

Let’s say you have 2 Shelly switches that report power usage named Dishwasher and Laundry Machine. Both devices have a switch entity and a power sensor. The devices and entities would previously look like this (type: entity name / state object friendly_name / entity_id):

  • Device: Dishwasher
    • Switch: Dishwasher Switch / Dishwasher Switch / switch.dishwasher_switch
    • Sensor: Dishwasher Power usage / Dishwasher Power usage / sensor.dishwasher_power_usage
  • Device: Laundry machine
    • Switch: Laundry machine Switch / Laundry machine Switch / switch.laundry_machine_switch
    • Sensor: Laundry machine Power usage / Laundry machine Power usage / sensor.laundry_machine_power_usage

Why is this a problem?

There is not a single source of truth for a device name because entities included the device name in their name.

Because we “solved” a problem for the UI and the entity_id by including the device name in the entity name, we now have this solution applied to all places where we use entities and have to work around this solution.

This naming scheme makes it unnecessarily difficult to migrate the UI towards hierarchical views of areas->devices->entities instead of long lists of entities.

· One min read

Before 2022.8, it was impossible to await config entry platforms forwards without a deadlock if one of the platforms loaded by the config entry was not already loaded.

Integrations need to be refactored to replace calls to hass.config_entries.async_setup_platforms with hass.config_entries.async_forward_entry_setups and/or await all hass.config_entries.async_forward_entry_setup to ensure that Home Assistant does not inadvertently reload the integration while entities and platforms are still being set up.

hass.config_entries.async_setup_platforms is scheduled to be removed in 2022.12.

· One min read

As of Home Assistant Core 2022.8, a Store (from homeassistant/helpers/storage.py) is defined as a Generic Store(Generic[_T]). It is recommended that the type of data being stored be defined in the Store definition. It should be JSON-serialisable (dict or list), for example:

  • Standard definition using a dict: self._store = Store[dict[str, int]](hass, STORAGE_VERSION, STORAGE_KEY)
  • Using a TypedDict: self._store = Store[EnergyPreferences](hass, STORAGE_VERSION, STORAGE_KEY)
  • Accessing an existing Store: store: Store[dict[str, Any]] = hass.data[DOMAIN][DATA_STORE]
  • Inherited Store: class MyCustomStorage(Store[list[int]]):

For more information about generics, see PEP 483

· One min read

WeatherEntity now supports temperature unit conversion following a similar pattern as the unit conversion supported by NumberEntity and SensorEntity.

Precipitation, pressure, temperature, visibility and wind speed are automatically converted according to the unit system configured by the users. In addition, users can override units for specific weather entities.

To make this possible, custom component integrations should be updated to override properties native_precipitation_unit, native_pressure, native_pressure_unit, native_temperature, native_temperature_unit,native_visibility, native_visibility_unit, native_wind_speed and native_wind_speed_unit, instead of precipitation_unit, pressure, pressure_unit, temperature, temperature_unit,visibility, visibility_unit, wind_speed and wind_speed_unit.

The same renaming has been done for the corresponding _attr_* attributes as well as for members of the Forecast typed dict

In Home Assistant Core 2023.1, overriding precipitation_unit, pressure, pressure_unit, temperature, temperature_unit,visibility, visibility_unit, wind_speed, wind_speed_unit, setting _attr_precipitation_unit, _attr_pressure, _attr_pressure_unit, _attr_temperature, _attr_temperature_unit, _attr_visibility, _attr_visibility_unit, _attr_wind_speed, _attr_wind_speed_unit and setting precipitation, pressure, temperature, templow, wind_speed on instances of Forecast is no longer supported.

· One min read

NumberEntity now supports temperature unit conversion following a similar pattern as the unit conversion supported by SensorEntity.

Temperature conversion will automatically be done for number entities with device class set to temperature to the temperature unit configured by the user.

To make this possible, custom component integrations should be updated to override properties native_max_value, native_min_value, native_step, native_unit_of_measurement, native_value instead of max_value, min_value, step, unit_of_measurement, value and to override methods async_set_native_value and set_native_value instead of async_set_value and set_value.

The same renaming has been done for _attr_* attributes as well as members of NumberEntityDescription.

In Home Assistant Core 2023.1, overriding async_set_value, max_value, min_value, set_value, step, unit_of_measurement, value, setting _attr_max_value, _attr_min_value, _attr_unit_of_measurement, _attr_step, _attr_value and setting max_value, min_value, unit_of_measurement, step on instances of NumberEntityDescription is no longer supported.

· One min read

Before 2022.7, it was possible to trigger a reload of a config entry while it was still setting up. Reloading during config entry setup often led to unexpected failure modes, which required restarting Home Assistant to get the config entry back in a good state. Attempting a reload during setup now raises the OperationNotAllowed exception.

· One min read

As of Home Assistant Core 2022.7, all RESULT_TYPE_* constants for data entry flow result types are deprecated:

  • RESULT_TYPE_FORM

  • RESULT_TYPE_CREATE_ENTRY

  • RESULT_TYPE_ABORT

  • RESULT_TYPE_EXTERNAL_STEP

  • RESULT_TYPE_EXTERNAL_STEP_DONE

  • RESULT_TYPE_SHOW_PROGRESS

  • RESULT_TYPE_SHOW_PROGRESS_DONE

  • RESULT_TYPE_MENU

    Use the new FlowResultType enum instead.