Skip to content

Commit d1b70a6

Browse files
committed
Fix device_state_attributes deprecation warning
1 parent 6fe412b commit d1b70a6

10 files changed

Lines changed: 28 additions & 28 deletions

File tree

custom_components/xiaomi_miot_raw/basic_dev_class.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def available(self):
210210
return self._available
211211

212212
@property
213-
def device_state_attributes(self):
213+
def extra_state_attributes(self):
214214
"""Return the state attributes of the device."""
215215
return self._state_attrs
216216

@@ -802,9 +802,9 @@ def available(self):
802802
return self._parent_device.available
803803

804804
@property
805-
def device_state_attributes(self):
805+
def extra_state_attributes(self):
806806
try:
807-
return self._parent_device.device_state_attributes or {}
807+
return self._parent_device.extra_state_attributes or {}
808808
except:
809809
return None
810810

@@ -826,7 +826,7 @@ async def async_update(self):
826826
if self._skip_update:
827827
self._skip_update = False
828828
return
829-
attrs = self._parent_device.device_state_attributes or {}
829+
attrs = self._parent_device.extra_state_attributes or {}
830830
self._state_attrs = attrs
831831
pass
832832

@@ -862,7 +862,7 @@ def available(self):
862862
@property
863863
def state(self):
864864
try:
865-
return STATE_ON if self.device_state_attributes.get(f"{self._did_prefix}switch_status") else STATE_OFF
865+
return STATE_ON if self.extra_state_attributes.get(f"{self._did_prefix}switch_status") else STATE_OFF
866866
except:
867867
return STATE_UNKNOWN
868868

custom_components/xiaomi_miot_raw/binary_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def state(self):
101101
def is_on(self):
102102
"""Return true if the binary sensor is on."""
103103
try:
104-
return self._parent_device.device_state_attributes[self._sensor_property]
104+
return self._parent_device.extra_state_attributes[self._sensor_property]
105105
except:
106106
return None
107107

custom_components/xiaomi_miot_raw/fan.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def speed(self):
283283
"""Return the current speed."""
284284
if not NEW_FAN:
285285
try:
286-
self._speed = self.get_key_by_value(self._ctrl_params['speed'],self.device_state_attributes[self._did_prefix + 'speed'])
286+
self._speed = self.get_key_by_value(self._ctrl_params['speed'],self.extra_state_attributes[self._did_prefix + 'speed'])
287287
except KeyError:
288288
self._speed = None
289289
return self._speed
@@ -294,7 +294,7 @@ def speed(self):
294294
def preset_mode(self):
295295
"""Return the current speed."""
296296
try:
297-
self._speed = self.get_key_by_value(self._ctrl_params['speed'],self.device_state_attributes[self._did_prefix + 'speed'])
297+
self._speed = self.get_key_by_value(self._ctrl_params['speed'],self.extra_state_attributes[self._did_prefix + 'speed'])
298298
except KeyError:
299299
self._speed = None
300300
return self._speed
@@ -310,7 +310,7 @@ def speed_count(self):
310310
@property
311311
def oscillating(self):
312312
"""Return the oscillation state."""
313-
return self.device_state_attributes.get(self._did_prefix + 'oscillate')
313+
return self.extra_state_attributes.get(self._did_prefix + 'oscillate')
314314

315315
async def async_oscillate(self, oscillating: bool) -> None:
316316
"""Set oscillation."""
@@ -416,7 +416,7 @@ def state(self):
416416
return self._state2
417417

418418
@property
419-
def device_state_attributes(self):
419+
def extra_state_attributes(self):
420420
return {ATTR_ATTRIBUTION: "在上方列表选择动作。选择后会立即执行。\n操作成功后,开关会短暂回弹。"}
421421

422422
async def async_update(self):
@@ -450,7 +450,7 @@ def speed_list(self) -> list:
450450
@property
451451
def speed(self):
452452
"""Return the current speed."""
453-
return self._parent_device.get_key_by_value(self._value_list, self._parent_device.device_state_attributes.get(self._did_prefix + self._field))
453+
return self._parent_device.get_key_by_value(self._value_list, self._parent_device.extra_state_attributes.get(self._did_prefix + self._field))
454454

455455
@property
456456
def percentage(self) -> str:
@@ -491,7 +491,7 @@ def state(self):
491491
return self._state2
492492

493493
@property
494-
def device_state_attributes(self):
494+
def extra_state_attributes(self):
495495
return {ATTR_ATTRIBUTION: f"可在此设置“{self._parent_device.name}”的 {self._field}。开关仅用于反馈操作是否成功,无控制功能。"}
496496

497497
async def async_update(self):

custom_components/xiaomi_miot_raw/light.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def supported_features(self):
235235
def brightness(self):
236236
"""Return the brightness of the light."""
237237
try:
238-
return self.convert_value(self.device_state_attributes[self._did_prefix + 'brightness'],"brightness",False,self._ctrl_params['brightness']['value_range'])
238+
return self.convert_value(self.extra_state_attributes[self._did_prefix + 'brightness'],"brightness",False,self._ctrl_params['brightness']['value_range'])
239239
except:
240240
return None
241241

@@ -291,7 +291,7 @@ async def async_turn_off(self, **kwargs):
291291
def color_temp(self):
292292
"""Return the color temperature in mired."""
293293
try:
294-
self._color_temp = self.convert_value(self.device_state_attributes[self._did_prefix + 'color_temperature'], "color_temperature") or 100
294+
self._color_temp = self.convert_value(self.extra_state_attributes[self._did_prefix + 'color_temperature'], "color_temperature") or 100
295295
except KeyError: pass
296296
return self._color_temp
297297

@@ -318,7 +318,7 @@ def effect_list(self):
318318
def effect(self):
319319
"""Return the current effect."""
320320
try:
321-
self._effect = self.get_key_by_value(self._ctrl_params['mode'],self.device_state_attributes[self._did_prefix + 'mode'])
321+
self._effect = self.get_key_by_value(self._ctrl_params['mode'],self.extra_state_attributes[self._did_prefix + 'mode'])
322322
except KeyError:
323323
self._effect = None
324324
return self._effect
@@ -327,7 +327,7 @@ def effect(self):
327327
def hs_color(self):
328328
"""Return the hs color value."""
329329
try:
330-
self._color = self.convert_value(self.device_state_attributes[self._did_prefix + 'color'],"color",False)
330+
self._color = self.convert_value(self.extra_state_attributes[self._did_prefix + 'color'],"color",False)
331331
except KeyError:
332332
self._color = None
333333
return self._color

custom_components/xiaomi_miot_raw/lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def __init__(self, parent_device, mapping, params, mitype):
116116

117117
@property
118118
def is_locked(self):
119-
return self.device_state_attributes.get(f"{self._did_prefix}physical_controls_locked") == True
119+
return self.extra_state_attributes.get(f"{self._did_prefix}physical_controls_locked") == True
120120

121121
async def async_lock(self, **kwargs):
122122
result = await self._parent_device.set_property_new(self._did_prefix + "physical_controls_locked", True)

custom_components/xiaomi_miot_raw/number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def name(self):
8080
def state(self):
8181
"""Return the state of the device."""
8282
try:
83-
return self._parent_device.device_state_attributes[self._full_did]
83+
return self._parent_device.extra_state_attributes[self._full_did]
8484
except:
8585
return None
8686

custom_components/xiaomi_miot_raw/select.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def options(self):
103103
@property
104104
def current_option(self):
105105
"""Return the selected entity option to represent the entity state."""
106-
return self._parent_device.device_state_attributes[self._full_did]
106+
return self._parent_device.extra_state_attributes[self._full_did]
107107

108108
async def async_select_option(self, option: str):
109109
"""Change the selected option."""

custom_components/xiaomi_miot_raw/sensor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def __init__(self, parent_device, mapping, params, mitype, others={}):
165165
def state(self):
166166
"""Return the state of the device."""
167167
try:
168-
return self._parent_device.device_state_attributes[self._sensor_property]
168+
return self._parent_device.extra_state_attributes[self._sensor_property]
169169
except:
170170
return None
171171

@@ -295,7 +295,7 @@ def state(self):
295295
return self.coordinator.data[0][0]
296296

297297
@property
298-
def device_state_attributes(self):
298+
def extra_state_attributes(self):
299299
"""Return the state attributes of the device."""
300300
return self._state_attrs
301301

@@ -490,7 +490,7 @@ def icon(self):
490490
return self._icon
491491

492492
@property
493-
def device_state_attributes(self):
493+
def extra_state_attributes(self):
494494
"""Return the state attributes of the device."""
495495
return self._state_attrs
496496

custom_components/xiaomi_miot_raw/switch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ async def async_turn_off(self) -> None:
106106

107107
@property
108108
def is_on(self):
109-
return self._parent_device.device_state_attributes.get(self._did_prefix + self._field)
109+
return self._parent_device.extra_state_attributes.get(self._did_prefix + self._field)
110110

111111
@property
112112
def state(self):
113113
return self._state
114114

115115
@property
116-
def device_state_attributes(self):
116+
def extra_state_attributes(self):
117117
return {}

custom_components/xiaomi_miot_raw/translations/en.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"xiaomi_account": {
3333
"title": "Log in Xiaomi Account",
34-
"description": "{hint}Enter your Xiaomi credentials.",
34+
"description": "{hint}Enter your Xiaomi Credentials.",
3535
"data": {
3636
"username": "Email/Xiaomi ID",
3737
"password": "Password",
@@ -60,7 +60,7 @@
6060
"description": "{device_info}"
6161
},
6262
"cloudinfo": {
63-
"title": "Account credentials",
63+
"title": "Account Credentials",
6464
"data": {
6565
"did": "did",
6666
"userId": "userId",
@@ -104,7 +104,7 @@
104104
"step": {
105105
"init": {
106106
"data": {
107-
"async_step_update_xiaomi_account": "Update Xiaomi Account credential and Server Location",
107+
"async_step_update_xiaomi_account": "Update Xiaomi Account Credential and Server Location",
108108
"async_step_select_devices": "Batch Adding Devices (Do not select with the one above)",
109109
"async_step_light_and_lock": "Show or Hide Switch for Indicator Light and Child Lock",
110110
"async_step_climate": "Attach a Sensor to Climate for Current Temperature",
@@ -117,7 +117,7 @@
117117
"title": "Would you like to..."
118118
},
119119
"update_xiaomi_account": {
120-
"title": "Update Xiaomi Account credential",
120+
"title": "Update Xiaomi Account Credential",
121121
"description": "{hint}Update password for “{username}”.",
122122
"data": {
123123
"username": "Email/Xiaomi ID",

0 commit comments

Comments
 (0)