Skip to content

Commit

Permalink
Fix unit constants and icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Apr 24, 2020
1 parent e3c1d52 commit 1869ba5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
14 changes: 8 additions & 6 deletions custom_components/jq300/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import voluptuous as vol
from homeassistant.components.sensor import DOMAIN as SENSOR
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_DEVICES, \
CONF_DEVICE_ID
CONF_DEVICE_ID, CONCENTRATION_PARTS_PER_BILLION, \
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER
from homeassistant.helpers import discovery
from requests import PreparedRequest

Expand All @@ -30,7 +31,7 @@
BASE_URL_DEVICE, USERAGENT_API, USERAGENT_DEVICE, QUERY_TIMEOUT, \
MSG_GENERIC_FAIL, MSG_LOGIN_FAIL, QUERY_METHOD_POST, MSG_BUSY, \
SENSORS, UPDATE_MIN_TIME, CONF_RECEIVE_TVOC_IN_PPB, \
CONF_RECEIVE_HCHO_IN_PPB, UNIT_PPM, UNIT_MGM3, UNIT_PPB
CONF_RECEIVE_HCHO_IN_PPB

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -108,7 +109,7 @@ def __init__(self, hass, username, password, receive_tvoc_in_ppb,
for sensor_id, data in SENSORS.items():
if (receive_tvoc_in_ppb and sensor_id == 8) \
or (receive_hcho_in_ppb and sensor_id == 7):
self._units[sensor_id] = UNIT_PPB
self._units[sensor_id] = CONCENTRATION_PARTS_PER_BILLION
else:
self._units[sensor_id] = data[1]

Expand Down Expand Up @@ -309,10 +310,11 @@ def get_sensors(self, device_id, force=False) -> Optional[dict]:

res[sensor_id] = float(sensor['content'])
if sensor_id == 8 and self._receive_tvoc_in_ppb:
res[sensor_id] *= 310 # M = 78.9516 g/mol
res[sensor_id] *= 310 # M(TVOC) = 78.9516 g/mol
elif sensor_id == 7 and self._receive_hcho_in_ppb:
res[sensor_id] *= 814 # M = 30.026 g/mol
if self._units[sensor_id] != UNIT_MGM3:
res[sensor_id] *= 814 # M(HCHO) = 30.026 g/mol
if self._units[sensor_id] != \
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER:
res[sensor_id] = int(res[sensor_id])

self._sensors[device_id] = res.copy()
Expand Down
33 changes: 15 additions & 18 deletions custom_components/jq300/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#

from homeassistant.const import TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE, \
DEVICE_CLASS_HUMIDITY
DEVICE_CLASS_HUMIDITY, UNIT_PERCENTAGE, \
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, \
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER, CONCENTRATION_PARTS_PER_MILLION

# Base component constants
DOMAIN = "jq300"
VERSION = "0.7.0"
VERSION = "0.7.1"
ISSUE_URL = "https://github.com/Limych/ha-jq300/issues"
ATTRIBUTION = None
DATA_JQ300 = 'jq300'
Expand Down Expand Up @@ -48,51 +50,46 @@

QUERY_TIMEOUT = 12

UNIT_MGM3 = 'mg/m³'
UNIT_UGM3 = 'µg/m³'
UNIT_PPM = 'ppm'
UNIT_PPB = 'ppb'

SENSORS = {
4: [
'Internal Temperature',
TEMP_CELSIUS,
'thermometer',
'mdi:thermometer',
DEVICE_CLASS_TEMPERATURE,
None,
],
5: [
'Humidity',
'%',
'water-percent',
UNIT_PERCENTAGE,
'mdi:water-percent',
DEVICE_CLASS_HUMIDITY,
None,
],
6: [
'PM 2.5',
UNIT_UGM3,
'air-filter',
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
'mdi:air-filter',
None,
'pm25',
],
7: [
'HCHO',
UNIT_MGM3,
'air-filter',
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
'mdi:cloud',
None,
None,
],
8: [
'TVOC',
UNIT_MGM3,
'air-filter',
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
'mdi:cloud',
None,
None,
],
9: [
'eCO2',
UNIT_PPM,
'molecule-co2',
CONCENTRATION_PARTS_PER_MILLION,
'mdi:periodic-table-co2',
None,
None,
],
Expand Down
2 changes: 1 addition & 1 deletion custom_components/jq300/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, hass, controller, device, sensor_id, sensor_state,
device['pt_name'], SENSORS.get(sensor_id)[0])
self._state = sensor_state
self._units = controller.units[sensor_id]
self._icon = 'mdi:{}'.format(SENSORS.get(sensor_id)[2])
self._icon = SENSORS.get(sensor_id)[2]
self._unique_id = '{}-{}-{}'.format(
self._controller.unique_id, self._device_id, sensor_id)
self._device_class = SENSORS.get(sensor_id)[3]
Expand Down
2 changes: 1 addition & 1 deletion tracker.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"jq300": {
"version": "0.7.0",
"version": "0.7.1",
"local_location": "/custom_components/jq300/__init__.py",
"remote_location": "https://raw.githubusercontent.com/Limych/ha-jq300/master/custom_components/jq300/__init__.py",
"visit_repo": "https://github.com/Limych/ha-jq300",
Expand Down

0 comments on commit 1869ba5

Please sign in to comment.