Skip to content

Commit ab8c508

Browse files
authored
Add fahrenheit support in miflora sensor (home-assistant#33136)
* add support for fahrenheit in miflora sensor * fix error introduced when resolving merge conflict * fix formatting
1 parent f0472f2 commit ab8c508

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

homeassistant/components/miflora/sensor.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
CONF_NAME,
1717
CONF_SCAN_INTERVAL,
1818
EVENT_HOMEASSISTANT_START,
19+
TEMP_FAHRENHEIT,
1920
UNIT_PERCENTAGE,
2021
)
2122
from homeassistant.core import callback
2223
import homeassistant.helpers.config_validation as cv
2324
from homeassistant.helpers.entity import Entity
2425
import homeassistant.util.dt as dt_util
26+
from homeassistant.util.temperature import celsius_to_fahrenheit
2527

2628
try:
2729
import bluepy.btle # noqa: F401 pylint: disable=unused-import
@@ -93,7 +95,11 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
9395

9496
for parameter in config[CONF_MONITORED_CONDITIONS]:
9597
name = SENSOR_TYPES[parameter][0]
96-
unit = SENSOR_TYPES[parameter][1]
98+
unit = (
99+
hass.config.units.temperature_unit
100+
if parameter == "temperature"
101+
else SENSOR_TYPES[parameter][1]
102+
)
97103
icon = SENSOR_TYPES[parameter][2]
98104

99105
prefix = config.get(CONF_NAME)
@@ -208,6 +214,8 @@ def update(self):
208214

209215
if data is not None:
210216
_LOGGER.debug("%s = %s", self.name, data)
217+
if self._unit == TEMP_FAHRENHEIT:
218+
data = celsius_to_fahrenheit(data)
211219
self.data.append(data)
212220
self.last_successful_update = dt_util.utcnow()
213221
else:

0 commit comments

Comments
 (0)