@@ -136,8 +136,6 @@ async def _async_setup(self):
136
136
This method will be called automatically during
137
137
coordinator.async_config_entry_first_refresh.
138
138
"""
139
- # await self._modbus_api.connect()
140
- # self._device = self._modbus_api.get_device()
141
139
await self .fetch_data ()
142
140
143
141
async def fetch_data (self , idx = None ):
@@ -197,8 +195,6 @@ async def _async_update_data(self):
197
195
# Grab active context variables to limit data required to be fetched from API
198
196
# Note: using context is not required if there is no need or ability to limit
199
197
# data retrieved from API.
200
- # listening_idx = set(self.async_contexts())
201
- # return await self._modbus_api.fetch_data(listening_idx)
202
198
try :
203
199
listening_idx = set (self .async_contexts ())
204
200
return await self .fetch_data (listening_idx )
@@ -242,23 +238,15 @@ def __init__(self, config_entry, modbus_item, modbus_api) -> None:
242
238
self ._attr_name = self ._modbus_item .name
243
239
244
240
dev_postfix = ""
245
- try :
246
- dev_postfix = "_" + self ._config_entry .data [CONF_DEVICE_POSTFIX ]
247
- except KeyError :
248
- warnings .warn ("Device postfix not defined, use default: " )
241
+ dev_postfix = "_" + self ._config_entry .data [CONF_DEVICE_POSTFIX ]
249
242
250
243
if dev_postfix == "_" :
251
244
dev_postfix = ""
252
245
253
246
dev_prefix = CONST .DEF_PREFIX
254
- try :
255
- dev_prefix = self ._config_entry .data [CONF_PREFIX ]
256
- except KeyError :
257
- warnings .warn ("Device prefix not defined, use default: " + CONST .DEF_PREFIX )
258
-
259
- self ._attr_unique_id = (
260
- dev_prefix + self ._modbus_item .name + dev_postfix
261
- ) # CONST.PREFIX + self._modbus_item.name
247
+ dev_prefix = self ._config_entry .data [CONF_PREFIX ]
248
+
249
+ self ._attr_unique_id = dev_prefix + self ._modbus_item .name + dev_postfix
262
250
self ._dev_device = self ._modbus_item .device + dev_postfix
263
251
self ._modbus_api = modbus_api
264
252
@@ -305,20 +293,6 @@ def calc_temperature(self, val: float):
305
293
# to optimize
306
294
return int (val ) / self ._divider
307
295
308
- # if val is None:
309
- # return None
310
- # if val == -32768:
311
- # # No Sensor installed
312
- # return -1
313
- # if val == -32767:
314
- # # Sensor broken
315
- # return -2
316
- # if val == 32768:
317
- # # Dont know. Whats this?
318
- # return None
319
- # if val in range(-500, 5000):
320
- # return int(val) / self._divider
321
-
322
296
def calc_percentage (self , val : float ):
323
297
"""Calculate percentage."""
324
298
if val is None :
@@ -424,10 +398,6 @@ def _handle_coordinator_update(self) -> None:
424
398
self ._attr_native_value = self .translate_val (self ._modbus_item .state )
425
399
self .async_write_ha_state ()
426
400
427
- # async def async_update(self) -> None:
428
- # # the synching is done by the ModbusObject of the entity
429
- # self._attr_native_value = self.translate_val(0)
430
-
431
401
def calc_power (self , val , x , y ):
432
402
"""Calculate heating power from power map."""
433
403
if val is None :
@@ -495,15 +465,10 @@ def _handle_coordinator_update(self) -> None:
495
465
496
466
async def async_set_native_value (self , value : float ) -> None :
497
467
await self .set_translate_val (value )
498
- # await self.coordinator.async_request_refresh()
499
468
self ._modbus_item .state = int (self .retranslate_val (value ))
500
469
self ._attr_native_value = self .translate_val (self ._modbus_item .state )
501
470
self .async_write_ha_state ()
502
471
503
- # async def async_update(self) -> None:
504
- # # the synching is done by the ModbusObject of the entity
505
- # self._attr_native_value = self.translate_val(self._modbus_item.state)
506
-
507
472
@property
508
473
def device_info (self ) -> DeviceInfo :
509
474
"""Return device info."""
@@ -543,11 +508,6 @@ def _handle_coordinator_update(self) -> None:
543
508
self ._attr_current_option = self .translate_val (self ._modbus_item .state )
544
509
self .async_write_ha_state ()
545
510
546
- # async def async_update(self) -> None:
547
- # # the synching is done by the ModbusObject of the entity
548
- # await self.coordinator.async_request_refresh()
549
- # self._attr_current_option = self.translate_val(self._modbus_item.state)
550
-
551
511
@property
552
512
def device_info (self ) -> DeviceInfo :
553
513
"""Return device info."""
0 commit comments