Skip to content

Commit 48a65d1

Browse files
committed
Add sensor states translation
1 parent 96ca4ca commit 48a65d1

File tree

8 files changed

+93
-79
lines changed

8 files changed

+93
-79
lines changed

.devcontainer/bootstrap.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ See separate [license file](LICENSE.md) for full text.
229229

230230
[component]: https://github.com/Limych/ha-gismeteo
231231
[commits-shield]: https://img.shields.io/github/commit-activity/y/Limych/ha-gismeteo.svg?style=popout
232-
[commits]: https://github.com/Limych/ha-gismeteo/commits/master
232+
[commits]: https://github.com/Limych/ha-gismeteo/commits/dev
233233
[hacs-shield]: https://img.shields.io/badge/HACS-Custom-orange.svg?style=popout
234234
[hacs]: https://hacs.xyz
235-
[exampleimg]: https://github.com/Limych/ha-gismeteo/raw/master/gismeteo_logo.jpg
235+
[exampleimg]: https://github.com/Limych/ha-gismeteo/raw/dev/gismeteo_logo.jpg
236236
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg?style=popout
237237
[forum]: https://community.home-assistant.io/t/gismeteo-weather-provider/109668
238238
[license]: https://github.com/Limych/ha-gismeteo/blob/main/LICENSE.md

custom_components/gismeteo/const.py

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@
2323
DEVICE_CLASS_PRESSURE,
2424
DEVICE_CLASS_TEMPERATURE,
2525
LENGTH_MILLIMETERS,
26+
PERCENTAGE,
2627
PRESSURE_HPA,
2728
SPEED_METERS_PER_SECOND,
2829
TEMP_CELSIUS,
2930
)
3031

31-
try:
32-
from homeassistant.const import PERCENTAGE
33-
except ImportError: # pragma: no cover
34-
from homeassistant.const import UNIT_PERCENTAGE as PERCENTAGE
35-
3632
# Base component constants
3733
NAME = "Gismeteo"
3834
DOMAIN = "gismeteo"
@@ -92,16 +88,6 @@
9288

9389
ENDPOINT_URL = "https://services.gismeteo.ru/inform-service/inf_chrome"
9490

95-
STARTUP_MESSAGE = f"""
96-
-------------------------------------------------------------------
97-
{NAME}
98-
Version: {VERSION}
99-
This is a custom integration!
100-
If you have ANY issues with this you need to open an issue here:
101-
{ISSUE_URL}
102-
-------------------------------------------------------------------
103-
"""
104-
10591
UPDATE_INTERVAL = timedelta(minutes=5)
10692

10793
CONDITION_FOG_CLASSES = [
@@ -128,44 +114,17 @@
128114
528,
129115
]
130116

131-
132-
ENDPOINT_URL = "https://services.gismeteo.ru/inform-service/inf_chrome"
133-
134117
MMHG2HPA = 1.333223684
135118
MS2KMH = 3.6
136119

137-
UPDATE_INTERVAL = timedelta(minutes=5)
138-
139-
CONDITION_FOG_CLASSES = [
140-
11,
141-
12,
142-
28,
143-
40,
144-
41,
145-
42,
146-
43,
147-
44,
148-
45,
149-
46,
150-
47,
151-
48,
152-
49,
153-
120,
154-
130,
155-
131,
156-
132,
157-
133,
158-
134,
159-
135,
160-
528,
161-
]
162-
163120
PRECIPITATION_AMOUNT = (0, 2, 6, 16)
164121

122+
DEVICE_CLASS_TPL = DOMAIN + "__{}"
123+
165124
SENSOR_TYPES = {
166125
"weather": {}, # => condition
167126
"condition": {
168-
ATTR_DEVICE_CLASS: None,
127+
ATTR_DEVICE_CLASS: DEVICE_CLASS_TPL.format("condition"),
169128
ATTR_ICON: None,
170129
ATTR_NAME: "Condition",
171130
ATTR_UNIT_OF_MEASUREMENT: None,
@@ -238,7 +197,7 @@
238197
},
239198
}
240199
FORECAST_SENSOR_TYPE = {
241-
ATTR_DEVICE_CLASS: None,
200+
ATTR_DEVICE_CLASS: DEVICE_CLASS_TPL.format("condition"),
242201
ATTR_ICON: None,
243202
ATTR_NAME: "3h Forecast",
244203
ATTR_UNIT_OF_MEASUREMENT: None,

custom_components/gismeteo/sensor.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
import logging
12-
from typing import List
12+
from typing import Any, Dict, List, Optional
1313

1414
import voluptuous as vol
1515
from homeassistant.components.sensor import PLATFORM_SCHEMA
@@ -188,33 +188,33 @@ def state(self):
188188
elif self.kind == "clouds":
189189
self._state = int(data.get(ATTR_WEATHER_CLOUDINESS) * 33.33)
190190
elif self.kind == "rain":
191-
if data.get(ATTR_WEATHER_PRECIPITATION_TYPE) in [1, 3]:
192-
self._state = (
191+
self._state = (
192+
(
193193
data.get(ATTR_WEATHER_PRECIPITATION_AMOUNT)
194194
or PRECIPITATION_AMOUNT[
195195
data.get(ATTR_WEATHER_PRECIPITATION_INTENSITY)
196196
]
197197
)
198-
self._unit_of_measurement = SENSOR_TYPES[self.kind][
199-
ATTR_UNIT_OF_MEASUREMENT
200-
]
201-
else:
202-
self._state = "not raining"
203-
self._unit_of_measurement = ""
198+
if data.get(ATTR_WEATHER_PRECIPITATION_TYPE) in [1, 3]
199+
else 0
200+
)
201+
self._unit_of_measurement = SENSOR_TYPES[self.kind][
202+
ATTR_UNIT_OF_MEASUREMENT
203+
]
204204
elif self.kind == "snow":
205-
if data.get(ATTR_WEATHER_PRECIPITATION_TYPE) in [2, 3]:
206-
self._state = (
205+
self._state = (
206+
(
207207
data.get(ATTR_WEATHER_PRECIPITATION_AMOUNT)
208208
or PRECIPITATION_AMOUNT[
209209
data.get(ATTR_WEATHER_PRECIPITATION_INTENSITY)
210210
]
211211
)
212-
self._unit_of_measurement = SENSOR_TYPES[self.kind][
213-
ATTR_UNIT_OF_MEASUREMENT
214-
]
215-
else:
216-
self._state = "not snowing"
217-
self._unit_of_measurement = ""
212+
if data.get(ATTR_WEATHER_PRECIPITATION_TYPE) in [2, 3]
213+
else 0
214+
)
215+
self._unit_of_measurement = SENSOR_TYPES[self.kind][
216+
ATTR_UNIT_OF_MEASUREMENT
217+
]
218218
elif self.kind == "storm":
219219
self._state = data.get(ATTR_WEATHER_STORM)
220220
elif self.kind == "geomagnetic":
@@ -228,22 +228,22 @@ def state(self):
228228
return self._state
229229

230230
@property
231-
def unit_of_measurement(self):
231+
def unit_of_measurement(self) -> Optional[str]:
232232
"""Return the unit of measurement of this entity, if any."""
233233
return self._unit_of_measurement
234234

235235
@property
236-
def icon(self):
236+
def icon(self) -> Optional[str]:
237237
"""Return the icon to use in the frontend, if any."""
238238
return SENSOR_TYPES[self.kind][ATTR_ICON]
239239

240240
@property
241-
def device_class(self):
241+
def device_class(self) -> Optional[str]:
242242
"""Return the device_class."""
243243
return SENSOR_TYPES[self.kind][ATTR_DEVICE_CLASS]
244244

245245
@property
246-
def device_state_attributes(self):
246+
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
247247
"""Return the state attributes."""
248248
attrs = self._gismeteo.attributes.copy()
249249
attrs[ATTR_ATTRIBUTION] = ATTRIBUTION
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"state": {
3+
"gismeteo__condition": {
4+
"clear-night": "Clear, night",
5+
"cloudy": "Cloudy",
6+
"exceptional": "Exceptional",
7+
"fog": "Fog",
8+
"hail": "Hail",
9+
"lightning": "Lightning",
10+
"lightning-rainy": "Lightning, rainy",
11+
"partlycloudy": "Partly cloudy",
12+
"pouring": "Pouring",
13+
"rainy": "Rainy",
14+
"snowy": "Snowy",
15+
"snowy-rainy": "Snowy, rainy",
16+
"sunny": "Sunny",
17+
"windy": "Windy",
18+
"windy-variant": "Windy"
19+
}
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"state": {
3+
"gismeteo__condition": {
4+
"clear-night": "\u042f\u0441\u043d\u043e, \u043d\u043e\u0447\u044c",
5+
"cloudy": "\u041e\u0431\u043b\u0430\u0447\u043d\u043e",
6+
"exceptional": "\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435",
7+
"fog": "\u0422\u0443\u043c\u0430\u043d",
8+
"hail": "\u0413\u0440\u0430\u0434",
9+
"lightning": "\u041c\u043e\u043b\u043d\u0438\u044f",
10+
"lightning-rainy": "\u041c\u043e\u043b\u043d\u0438\u044f, \u0434\u043e\u0436\u0434\u044c",
11+
"partlycloudy": "\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u0441\u0442\u044c",
12+
"pouring": "\u041b\u0438\u0432\u0435\u043d\u044c",
13+
"rainy": "\u0414\u043e\u0436\u0434\u044c",
14+
"snowy": "\u0421\u043d\u0435\u0433",
15+
"snowy-rainy": "\u0421\u043d\u0435\u0433 \u0441 \u0434\u043e\u0436\u0434\u0435\u043c",
16+
"sunny": "\u042f\u0441\u043d\u043e",
17+
"windy": "\u0412\u0435\u0442\u0440\u0435\u043d\u043e",
18+
"windy-variant": "\u0412\u0435\u0442\u0440\u0435\u043d\u043e"
19+
}
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"state": {
3+
"gismeteo__condition": {
4+
"clear-night": "\u042f\u0441\u043d\u043e, \u043d\u0456\u0447",
5+
"cloudy": "\u0425\u043c\u0430\u0440\u043d\u043e",
6+
"exceptional": "\u041f\u043e\u043f\u0435\u0440\u0435\u0434\u0436\u0435\u043d\u043d\u044f",
7+
"fog": "\u0422\u0443\u043c\u0430\u043d",
8+
"hail": "\u0413\u0440\u0430\u0434",
9+
"lightning": "\u0411\u043b\u0438\u0441\u043a\u0430\u0432\u043a\u0430",
10+
"lightning-rainy": "\u0411\u043b\u0438\u0441\u043a\u0430\u0432\u043a\u0430, \u0434\u043e\u0449",
11+
"partlycloudy": "\u041d\u0435\u0432\u0435\u043b\u0438\u043a\u0430 \u0445\u043c\u0430\u0440\u043d\u0456\u0441\u0442\u044c",
12+
"pouring": "\u0417\u043b\u0438\u0432\u0430",
13+
"rainy": "\u0414\u043e\u0449\u043e\u0432\u0430",
14+
"snowy": "\u0421\u043d\u0456\u0436\u043d\u043e",
15+
"snowy-rainy": "\u0421\u043d\u0456\u0433, \u0434\u043e\u0449",
16+
"sunny": "\u0421\u043e\u043d\u044f\u0447\u043d\u043e",
17+
"windy": "\u0412\u0456\u0442\u0440\u044f\u043d\u043e",
18+
"windy-variant": "\u0412\u0456\u0442\u0440\u044f\u043d\u043e"
19+
}
20+
}
21+
}

info.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ I put a lot of work into making this repo and component available and updated to
6363

6464
[component]: https://github.com/Limych/ha-gismeteo
6565
[commits-shield]: https://img.shields.io/github/commit-activity/y/Limych/ha-gismeteo.svg?style=popout
66-
[commits]: https://github.com/Limych/ha-gismeteo/commits/master
66+
[commits]: https://github.com/Limych/ha-gismeteo/commits/dev
6767
[hacs-shield]: https://img.shields.io/badge/HACS-Custom-orange.svg?style=popout
6868
[hacs]: https://hacs.xyz
69-
[exampleimg]: https://github.com/Limych/ha-gismeteo/raw/master/gismeteo_logo.jpg
69+
[exampleimg]: https://github.com/Limych/ha-gismeteo/raw/dev/gismeteo_logo.jpg
7070
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg?style=popout
7171
[forum]: https://community.home-assistant.io/t/gismeteo-weather-provider/109668
7272
[license]: https://github.com/Limych/ha-gismeteo/blob/main/LICENSE.md

0 commit comments

Comments
 (0)