Compare commits

...

5 Commits

Author SHA1 Message Date
Викторов Андрей Германович
4145eebbdd Bump version: 1.0.10b6 → 1.0.10b7 2021-10-28 15:02:18 +03:00
Викторов Андрей Германович
d4dddc61fd add sensor filters 2021-10-28 15:02:11 +03:00
Викторов Андрей Германович
bc34c1a0b3 add sensor filters 2021-09-21 17:49:43 +03:00
Викторов Андрей Германович
2662b9c3bd Bump version: 1.0.10b5 → 1.0.10b6 2021-09-21 17:33:30 +03:00
Викторов Андрей Германович
8399bbd1de fix focs about i2c id 2021-09-21 17:33:22 +03:00
4 changed files with 17 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.10b5
current_version = 1.0.10b7
parse = (?P<major>\d+)(\.(?P<minor>\d+))(\.(?P<patch>\d+))(?P<release>[bf]*)(?P<build>\d*)
commit = True
tag = True

View File

@@ -15,5 +15,5 @@
"@andvikt"
],
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
"version": "v1.0.10b5"
"version": "v1.0.10b7"
}

View File

@@ -165,6 +165,14 @@ class MegaI2C(FilterBadValues):
def customize(self):
return super().customize.get(self.id_suffix, {}) or {}
@property
def extra_state_attributes(self):
attrs = super().extra_state_attributes or {}
attrs.update({
'i2c_id': self.id_suffix,
})
return attrs
@property
def device_class(self):
return self._device_class
@@ -179,7 +187,7 @@ class MegaI2C(FilterBadValues):
ret = self.mega.values.get(self._params)
if self.customize.get(CONF_HEX_TO_FLOAT):
try:
ret = struct.unpack('!f', bytes.fromhex('41973333'))[0]
ret = struct.unpack('!f', bytes.fromhex(ret))[0]
except:
self.lg.warning(f'could not convert {ret} form hex to float')
tmpl: Template = self.customize.get(CONF_CONV_TEMPLATE, self.customize.get(CONF_VALUE_TEMPLATE))
@@ -220,6 +228,7 @@ class Mega1WSensor(FilterBadValues):
self._device_class = device_class
self._unit_of_measurement = unit_of_measurement
self.mega.sensors.append(self)
self.prev_value = None
@property
def unit_of_measurement(self):
@@ -273,7 +282,8 @@ class Mega1WSensor(FilterBadValues):
ret = float(ret)
ret = str(ret)
except:
ret = None
self.lg.warning(f'could not convert to float "{ret}"')
ret = self.prev_value
if self.customize.get(CONF_HEX_TO_FLOAT):
try:
ret = struct.unpack('!f', bytes.fromhex(ret))[0]
@@ -288,6 +298,7 @@ class Mega1WSensor(FilterBadValues):
except:
pass
ret = self.filter_value(ret)
self.prev_value = ret
return str(ret)
@property

View File

@@ -189,10 +189,10 @@ some_led2:
# конфиг
```
#### i2c {: #i2c}
Для сенсоров i2c адресация конфига такая:
Для сенсоров i2c нужно так же указать id сенсора, который можно посмотреть в атрибутах объекта на [странице разработчика](https://my.home-assistant.io/redirect/developer_states/).
```yaml
36:
htu21d_humidity: # entity_id сенсора без приставки sensor., видно в интерфейсе HA
htu21d_humidity: # i2c_id
# конфиг
```
[Подробнее про i2c](i2c.md)