Skip to content

Commit c60d4bc

Browse files
authored
Merge pull request #1164 from custom-components/remove_rounding
BREAKING CHANGE - Remove rounding option
2 parents a071005 + 5e94d18 commit c60d4bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+235
-314
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ body:
1414
attributes:
1515
label: What happened?
1616
description: Explain the bug you found?
17-
placeholder:
17+
placeholder:
1818
validations:
1919
required: true
2020
- type: input
2121
id: sensortype
2222
attributes:
2323
label: Sensor type
2424
description: If the bug is related to a specific sensor, describe the sensor type.
25-
placeholder:
25+
placeholder:
2626
validations:
2727
required: false
2828
- type: textarea

.github/ISSUE_TEMPLATE/new_sensor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ body:
88
- type: markdown
99
attributes:
1010
value: |
11-
Use this form to request support for a new sensor only. Bugs can be reported with a normal issue.
11+
Use this form to request support for a new sensor only. Bugs can be reported with a normal issue.
1212
- type: input
1313
id: sensor
1414
attributes:

.github/workflows/test_commit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Setup Python
3131
uses: "actions/setup-python@v4"
3232
with:
33-
python-version: "3.9"
33+
python-version: "3.10"
3434
- name: Install requirements
3535
run: python3 -m pip install -r requirements_test.txt
3636
- name: Run pytest

.pre-commit-config.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: end-of-file-fixer
6+
- id: check-yaml
7+
- id: trailing-whitespace

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
"python.testing.pytestArgs": [
2626
"custom_components"
2727
]
28-
}
28+
}

custom_components/ble_monitor/__init__.py

-26
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
CONF_BATT_ENTITIES,
3838
CONF_BT_AUTO_RESTART,
3939
CONF_BT_INTERFACE,
40-
CONF_DECIMALS,
41-
CONF_DEVICE_DECIMALS,
4240
CONF_DEVICE_ENCRYPTION_KEY,
4341
CONF_DEVICE_USE_MEDIAN,
4442
CONF_DEVICE_REPORT_UNKNOWN,
@@ -60,8 +58,6 @@
6058
DEFAULT_ACTIVE_SCAN,
6159
DEFAULT_BATT_ENTITIES,
6260
DEFAULT_BT_AUTO_RESTART,
63-
DEFAULT_DECIMALS,
64-
DEFAULT_DEVICE_DECIMALS,
6561
DEFAULT_DEVICE_REPORT_UNKNOWN,
6662
DEFAULT_DEVICE_RESTORE_STATE,
6763
DEFAULT_DEVICE_RESET_TIMER,
@@ -113,9 +109,6 @@
113109
cv.matches_regex(AES128KEY24_REGEX), cv.matches_regex(AES128KEY32_REGEX)
114110
),
115111
vol.Optional(CONF_TEMPERATURE_UNIT): cv.temperature_unit,
116-
vol.Optional(CONF_DEVICE_DECIMALS, default=DEFAULT_DEVICE_DECIMALS): vol.In(
117-
[DEFAULT_DEVICE_DECIMALS, 0, 1, 2, 3, 4]
118-
),
119112
vol.Optional(CONF_DEVICE_USE_MEDIAN, default=DEFAULT_DEVICE_USE_MEDIAN): vol.In(
120113
[DEFAULT_DEVICE_USE_MEDIAN, True, False]
121114
),
@@ -153,9 +146,6 @@
153146
vol.Optional(
154147
CONF_BT_AUTO_RESTART, default=DEFAULT_BT_AUTO_RESTART
155148
): cv.boolean,
156-
vol.Optional(
157-
CONF_DECIMALS, default=DEFAULT_DECIMALS
158-
): cv.positive_int,
159149
vol.Optional(CONF_PERIOD, default=DEFAULT_PERIOD): cv.positive_int,
160150
vol.Optional(
161151
CONF_LOG_SPIKES, default=DEFAULT_LOG_SPIKES
@@ -439,22 +429,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
439429

440430
async def async_migrate_entry(hass, config_entry):
441431
"""Migrate config entry to new version."""
442-
if config_entry.version == 2:
443-
options = dict(config_entry.options)
444-
options[CONF_REPORT_UNKNOWN] = "Off"
445-
446-
config_entry.version = 3
447-
hass.config_entries.async_update_entry(config_entry, options=options)
448-
_LOGGER.info("Migrated config entry to version %d", config_entry.version)
449-
450-
if config_entry.version == 3:
451-
options = dict(config_entry.options)
452-
if options[CONF_BT_INTERFACE] == ["00:00:00:00:00:00"]:
453-
options[CONF_BT_INTERFACE] = ["disable"]
454-
455-
config_entry.version = 4
456-
hass.config_entries.async_update_entry(config_entry, options=options)
457-
_LOGGER.info("Migrated config entry to version %d", config_entry.version)
458432

459433
if config_entry.version == 4:
460434
options = dict(config_entry.options)

custom_components/ble_monitor/binary_sensor.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ async def async_add_binary_sensor(key, device_model, firmware, auto_sensors, man
115115
if key not in sensors_by_key:
116116
sensors_by_key[key] = {}
117117
if measurement not in sensors_by_key[key]:
118-
description = [item for item in BINARY_SENSOR_TYPES if item.key is measurement][0]
119-
sensors[measurement] = globals()[description.sensor_class](
120-
self.config, key, device_model, firmware, description, manufacturer
118+
entity_description = [item for item in BINARY_SENSOR_TYPES if item.key is measurement][0]
119+
sensors[measurement] = globals()[entity_description.sensor_class](
120+
self.config, key, device_model, firmware, entity_description, manufacturer
121121
)
122122
self.add_entities([sensors[measurement]])
123123
sensors_by_key[key].update(sensors)
@@ -129,9 +129,9 @@ async def async_add_binary_sensor(key, device_model, firmware, auto_sensors, man
129129
sensors = {}
130130
sensors_by_key[key] = {}
131131
for measurement in device_sensors:
132-
description = [item for item in BINARY_SENSOR_TYPES if item.key is measurement][0]
133-
sensors[measurement] = globals()[description.sensor_class](
134-
self.config, key, device_model, firmware, description, manufacturer
132+
entity_description = [item for item in BINARY_SENSOR_TYPES if item.key is measurement][0]
133+
sensors[measurement] = globals()[entity_description.sensor_class](
134+
self.config, key, device_model, firmware, entity_description, manufacturer
135135
)
136136
self.add_entities([sensors[measurement]])
137137
sensors_by_key[key] = sensors
@@ -288,11 +288,11 @@ def __init__(
288288
key: str,
289289
devtype: str,
290290
firmware: str,
291-
description: BLEMonitorBinarySensorEntityDescription,
291+
entity_description: BLEMonitorBinarySensorEntityDescription,
292292
manufacturer=None
293293
) -> None:
294294
"""Initialize the binary sensor."""
295-
self.entity_description = description
295+
self.entity_description = entity_description
296296
self._config = config
297297
self._type = detect_conf_type(key)
298298

@@ -321,10 +321,10 @@ def __init__(
321321
self._reset_timer = self._device_settings["reset_timer"]
322322
self._newstate = None
323323

324-
self._attr_name = f"{description.name} {self._device_name}"
325-
self._attr_unique_id = f"{description.unique_id}{self._device_name}"
324+
self._attr_name = f"{self.entity_description.name} {self._device_name}"
325+
self._attr_unique_id = f"{self.entity_description.unique_id}{self._device_name}"
326326
self._attr_should_poll = False
327-
self._attr_force_update = description.force_update
327+
self._attr_force_update = self.entity_description.force_update
328328
self._attr_extra_state_attributes = self._extra_state_attributes
329329

330330
self._attr_device_info = {
@@ -512,9 +512,9 @@ async def async_update(self):
512512
class MotionBinarySensor(BaseBinarySensor):
513513
"""Representation of a Motion Binary Sensor."""
514514

515-
def __init__(self, config, key, devtype, firmware, description, manufacturer=None):
515+
def __init__(self, config, key, devtype, firmware, entity_description, manufacturer=None):
516516
"""Initialize the sensor."""
517-
super().__init__(config, key, devtype, firmware, description, manufacturer)
517+
super().__init__(config, key, devtype, firmware, entity_description, manufacturer)
518518
self._start_timer = None
519519

520520
def reset_state(self, event=None):

custom_components/ble_monitor/ble_parser/sensirion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def parse_sensirion(self, data, complete_local_name, source_mac, rssi):
7070

7171
'''
7272
The following functions are based on Sensirion_GadgetBle_Lib.cpp from https://github.com/Sensirion/arduino-ble-gadget/
73-
support from other devices should be easily added by looking at GadgetBle::setDataType and updating _parse_data_type
73+
support from other devices should be easily added by looking at GadgetBle::setDataType and updating _parse_data_type
7474
accordingly. Note that the device name also has to be added to the SENSIRION_DEVICES list.
7575
'''
7676

custom_components/ble_monitor/config_flow.py

-24
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
CONF_ACTIVE_SCAN,
3131
CONF_BT_AUTO_RESTART,
3232
CONF_BT_INTERFACE,
33-
CONF_DECIMALS,
3433
CONF_DEVICE_ENCRYPTION_KEY,
35-
CONF_DEVICE_DECIMALS,
3634
CONF_DEVICE_USE_MEDIAN,
3735
CONF_DEVICE_REPORT_UNKNOWN,
3836
CONF_DEVICE_RESTORE_STATE,
@@ -50,8 +48,6 @@
5048
CONFIG_IS_FLOW,
5149
DEFAULT_ACTIVE_SCAN,
5250
DEFAULT_BT_AUTO_RESTART,
53-
DEFAULT_DECIMALS,
54-
DEFAULT_DEVICE_DECIMALS,
5551
DEFAULT_DEVICE_ENCRYPTION_KEY,
5652
DEFAULT_DEVICE_MAC,
5753
DEFAULT_DEVICE_UUID,
@@ -93,9 +89,6 @@
9389
vol.Optional(CONF_TEMPERATURE_UNIT, default=TEMP_CELSIUS): vol.In(
9490
[TEMP_CELSIUS, TEMP_FAHRENHEIT]
9591
),
96-
vol.Optional(CONF_DEVICE_DECIMALS, default=DEFAULT_DEVICE_DECIMALS): vol.In(
97-
[DEFAULT_DEVICE_DECIMALS, 0, 1, 2, 3]
98-
),
9992
vol.Optional(CONF_DEVICE_USE_MEDIAN, default=DEFAULT_DEVICE_USE_MEDIAN): vol.In(
10093
[DEFAULT_DEVICE_USE_MEDIAN, True, False]
10194
),
@@ -134,7 +127,6 @@
134127
vol.Optional(CONF_DISCOVERY, default=DEFAULT_DISCOVERY): cv.boolean,
135128
vol.Optional(CONF_USE_MEDIAN, default=DEFAULT_USE_MEDIAN): cv.boolean,
136129
vol.Optional(CONF_PERIOD, default=DEFAULT_PERIOD): cv.positive_int,
137-
vol.Optional(CONF_DECIMALS, default=DEFAULT_DECIMALS): cv.positive_int,
138130
vol.Optional(CONF_LOG_SPIKES, default=DEFAULT_LOG_SPIKES): cv.boolean,
139131
vol.Optional(CONF_RESTORE_STATE, default=DEFAULT_RESTORE_STATE): cv.boolean,
140132
vol.Optional(CONF_REPORT_UNKNOWN, default=DEFAULT_REPORT_UNKNOWN): vol.In(
@@ -245,10 +237,6 @@ async def async_step_add_remove_device(self, user_input=None):
245237
CONF_TEMPERATURE_UNIT,
246238
default=user_input[CONF_TEMPERATURE_UNIT],
247239
): vol.In([TEMP_CELSIUS, TEMP_FAHRENHEIT]),
248-
vol.Optional(
249-
CONF_DEVICE_DECIMALS,
250-
default=user_input[CONF_DEVICE_DECIMALS],
251-
): vol.In([DEFAULT_DEVICE_DECIMALS, 0, 1, 2, 3]),
252240
vol.Optional(
253241
CONF_DEVICE_USE_MEDIAN,
254242
default=user_input[CONF_DEVICE_USE_MEDIAN],
@@ -329,12 +317,6 @@ async def async_step_add_remove_device(self, user_input=None):
329317
CONF_TEMPERATURE_UNIT, TEMP_CELSIUS
330318
),
331319
): vol.In([TEMP_CELSIUS, TEMP_FAHRENHEIT]),
332-
vol.Optional(
333-
CONF_DEVICE_DECIMALS,
334-
default=self._sel_device.get(
335-
CONF_DEVICE_DECIMALS, DEFAULT_DEVICE_DECIMALS
336-
),
337-
): vol.In([DEFAULT_DEVICE_DECIMALS, 0, 1, 2, 3]),
338320
vol.Optional(
339321
CONF_DEVICE_USE_MEDIAN,
340322
default=self._sel_device.get(
@@ -488,12 +470,6 @@ def _show_main_form(self, errors=None):
488470
CONF_USE_MEDIAN, DEFAULT_USE_MEDIAN
489471
),
490472
): cv.boolean,
491-
vol.Optional(
492-
CONF_DECIMALS,
493-
default=self.config_entry.options.get(
494-
CONF_DECIMALS, DEFAULT_DECIMALS
495-
),
496-
): cv.positive_int,
497473
vol.Optional(
498474
CONF_LOG_SPIKES,
499475
default=self.config_entry.options.get(

0 commit comments

Comments
 (0)