Skip to main content

Deprecating unit conversion utilities

· One min read

As of Home Assistant Core 2022.10, the following utilities are deprecated:

  • homeassistant/util/distance
  • homeassistant/util/pressure
  • homeassistant/util/speed
  • homeassistant/util/temperature
  • homeassistant/util/volume

Please use the corresponding static classes from homeassistant/util/unit_conversion:

  • DistanceConverter
  • PressureConverter
  • SpeedConverter
  • TemperatureConverter
  • VolumeConverter

New sensor device classes

· One min read

Several new sensor device classes have been added:

  • distance, a distance measured in either of cm, ft, in, km, m, mi, mm, yd
  • speed, a speed measured in either of ft/s, in/d, in/h, km/h, kn, m/s, mm/d, mph
  • volume, a volume measured in either of fl. oz., ft³, gal, L, mL,
  • weight, a mass measured in either of g, kg, lb, mg, oz, µg

Like pressure and temperatures sensors, users can freely choose the display unit from the UI for sensors using any of the new device classes.

Long term statistics

Long term statistics will store distance as m, speed as m/s, volume as and weight as g. For existing sensors which are modified to one of the new device classes, statistics will continue to be recorded in the sensor's state_unit but users will be given the option to have existing statistics converted to the normalized unit.

Bluetooth async_track_unavailable API changes for 2022.10

· One min read

For Home Assistant Core 2022.10 we have changed the async_track_unavailable bluetooth API to send the last BluetoothServiceInfoBleak to the callback instead of the address.

Below is a new example of the usage:

from homeassistant.components import bluetooth

def _unavailable_callback(info: bluetooth.BluetoothServiceInfoBleak) -> None:
_LOGGER.debug("%s is no longer seen", info.address)

cancel = bluetooth.async_track_unavailable(hass, _unavailable_callback, "44:44:33:11:23:42", connectable=True)

Deprecating media player constants

· One min read

As of Home Assistant Core 2022.10, the following media player constants are deprecated:

  • MEDIA_CLASS_ALBUM

  • MEDIA_CLASS_APP

  • MEDIA_CLASS_ARTIST

  • MEDIA_CLASS_CHANNEL

  • MEDIA_CLASS_COMPOSER

  • MEDIA_CLASS_CONTRIBUTING_ARTIST

  • MEDIA_CLASS_DIRECTORY

  • MEDIA_CLASS_EPISODE

  • MEDIA_CLASS_GAME

  • MEDIA_CLASS_GENRE

  • MEDIA_CLASS_IMAGE

  • MEDIA_CLASS_MOVIE

  • MEDIA_CLASS_MUSIC

  • MEDIA_CLASS_PLAYLIST

  • MEDIA_CLASS_PODCAST

  • MEDIA_CLASS_SEASON

  • MEDIA_CLASS_TRACK

  • MEDIA_CLASS_TV_SHOW

  • MEDIA_CLASS_URL

  • MEDIA_CLASS_VIDEO

  • MEDIA_TYPE_ALBUM

  • MEDIA_TYPE_APP

  • MEDIA_TYPE_APPS

  • MEDIA_TYPE_ARTIST

  • MEDIA_TYPE_CHANNEL

  • MEDIA_TYPE_CHANNELS

  • MEDIA_TYPE_COMPOSER

  • MEDIA_TYPE_CONTRIBUTING_ARTIST

  • MEDIA_TYPE_EPISODE

  • MEDIA_TYPE_GAME

  • MEDIA_TYPE_GENRE

  • MEDIA_TYPE_IMAGE

  • MEDIA_TYPE_MOVIE

  • MEDIA_TYPE_MUSIC

  • MEDIA_TYPE_PLAYLIST

  • MEDIA_TYPE_PODCAST

  • MEDIA_TYPE_SEASON

  • MEDIA_TYPE_TRACK

  • MEDIA_TYPE_TVSHOW

  • MEDIA_TYPE_URL

  • MEDIA_TYPE_VIDEO

  • REPEAT_MODE_ALL

  • REPEAT_MODE_OFF

  • REPEAT_MODE_ONE

  • REPEAT_MODES

Use the new MediaClass, MediaType, and RepeatMode enum instead.

The use of STATE_* constants to reflect media player state is also deprecated. Please use the new MediaPlayerState enum instead.

The issue registry has been moved to homeassistant.helpers

· One min read

The issue registry has been moved from homeassistant.components.repairs to homeassistant.helpers and is now loaded together with the other registries very early during bootstrapping, before setup of any integrations.

This allows creating issues during validation of the configuration.

Globally available HomeAssistant object (hass)

· One min read

It's now possible to get a reference to the HomeAssistant instance by calling core.async_get_hass().

Although this means it's no longer strictly necessary to pass hass around, the recommendation is still to only use core.async_get_hass where it's very cumbersome or downright impossible to pass hass to the code which needs it. An example where this can be useful is voluptuous validators, which previously couldn't access hass because voluptuous has no way of passing user data to validators.

@callback
def async_get_hass() -> HomeAssistant:
"""Return the HomeAssistant instance.
Raises LookupError if no HomeAssistant instance is available.
This should be used where it's very cumbersome or downright impossible to pass
hass to the code which needs it.
"""

AutomationActionType deprecation for 2022.9

· 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.

Bluetooth passive sensor API changes for 2022.9

· 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).

Device tracker deprecations for 2022.9

· 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