Skip to content

Commit b9af387

Browse files
authored
Blog post about one preferred encoding to represent the μ-sign (#2757)
1 parent ce69203 commit b9af387

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
author: Jan Bouwhuis
3+
authorURL: https://github.com/jbouwh
4+
authorImageURL: https://avatars.githubusercontent.com/u/7188918?s=96&v=4
5+
title: Standardize encoding of μ in units of measurement
6+
---
7+
8+
## One preferred encoding to represent μ in units of measurement
9+
10+
The unit prefix μ is used by unit of measurement constants like μV and μS.
11+
There are however two different Unicode encodings of μ:
12+
13+
1. The [MICRO SIGN](https://www.compart.com/en/unicode/U+00B5)
14+
2. The [Greek Small Letter Mu](https://www.compart.com/en/unicode/U+03BC)
15+
16+
Home Assistant previously mixed the two encodings, which caused issues because string comparisons between the two encodings would fail causing unit of measurement validations to fail.
17+
18+
We chose the "Greek Small Letter Mu" because the "MICRO SIGN" encoding is there for compatibility with old 8-bit western European character sets, and the unicode consortium recommends against using it.
19+
20+
With [#144853](https://github.com/home-assistant/core/pull/144853) we have fixed this in the core of Home Assistant by consequently using the Greek Small Letter Mu version to encode μ. In Python literal strings this variant is encoded as `"\u03bc"`.
21+
22+
Developers should check if their code and libraries have a dependency with the ambiguous MICRO SIGN (μ) `"\u00b5"`, and migrate their code to use the Greek Small Letter Mu `"\u03bc"` instead to avoid issues.
23+
24+
The `sensor` and `number` entity platforms now include a built-in feature to automatically convert units that use the ambiguous MICRO SIGN (μ) encoding.
25+
26+
## Find instances in Visual Studio Code
27+
28+
In Visual Studio Code, enable **Match Case** in the **Search** (files) panel to find only the chosen encoding. Copy the exact μ character from above and paste it into the search box. The editor’s page search matches all variants; use the global search instead.
29+
## New linter
30+
31+
To avoid issues with new or changed code, [#144853](https://github.com/home-assistant/core/pull/144853) adds a linter that warns about incorrect literal assignments using the non-preferred encoding of μ.

0 commit comments

Comments
 (0)