Skip to content

Commit

Permalink
Import from homeassistant sensorplatform and use
Browse files Browse the repository at this point in the history
  • Loading branch information
bouwew committed Oct 23, 2021
1 parent 511fd3c commit 8f761af
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions custom_components/sems2mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@
import paho.mqtt.client as mqtt

from homeassistant.components.sensor import (

DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL,
STATE_CLASS_TOTAL_INCREASING,
)
from homeassistant.const import (
CONF_PASSWORD, CONF_USERNAME,
Expand Down Expand Up @@ -220,8 +228,8 @@ def create_device(model):
'value_template':'{{ value_json.pgrid_w }}',
'icon':'mdi:solar-power',
'state_topic':'sems/sensors',
'state_class': "measurement",
'device_class': 'power',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_POWER,
'unique_id':'sems_solar_power_sensor',
'device': create_device(data['type'])
}
Expand All @@ -231,8 +239,8 @@ def create_device(model):
'value_template':'{{ value_json.temperature }}',
'icon':'mdi:thermometer',
'state_topic':'sems/sensors',
'state_class': "measurement",
'device_class': 'temperature',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_TEMPERATURE,
'unique_id':'sems_inverter_temperature_sensor',
'device': create_device(data['type'])
}
Expand All @@ -242,8 +250,8 @@ def create_device(model):
'value_template':'{{ value_json.eday_kwh }}',
'icon':'mdi:flash',
'state_topic':'sems/sensors',
'state_class': "total",
'device_class': 'energy',
'state_class': STATE_CLASS_TOTAL,
'device_class': DEVICE_CLASS_ENERGY,
'unique_id':'sems_produced_today_sensor',
'device': create_device(data['type'])
}
Expand All @@ -253,8 +261,8 @@ def create_device(model):
'value_template':'{{ value_json.etotal_kwh }}',
'icon':'mdi:flash',
'state_topic':'sems/sensors',
'state_class': "total_increasing",
'device_class': 'energy',
'state_class': STATE_CLASS_TOTAL_INCREASING,
'device_class': DEVICE_CLASS_ENERGY,
'unique_id':'sems_produced_total_sensor',
'device': create_device(data['type'])
}
Expand All @@ -264,8 +272,8 @@ def create_device(model):
'value_template':'{{ value_json.emonth_kwh }}',
'icon':'mdi:flash',
'state_topic':'sems/sensors',
'state_class': "total",
'device_class': 'energy',
'state_class': STATE_CLASS_TOTAL,
'device_class': DEVICE_CLASS_ENERGY,
'unique_id':'sems_produced_this_month_sensor',
'device': create_device(data['type'])
}
Expand All @@ -275,8 +283,8 @@ def create_device(model):
'value_template':'{{ value_json.grid_voltage }}',
'icon':'mdi:current-ac',
'state_topic':'sems/sensors',
'state_class': "measurement",
'device_class': 'voltage',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_VOLTAGE,
'unique_id':'sems_grid_voltage_sensor',
'device': create_device(data['type'])
}
Expand All @@ -286,8 +294,8 @@ def create_device(model):
'value_template':'{{ value_json.grid_current }}',
'icon':'mdi:current-ac',
'state_topic':'sems/sensors',
'state_class': "measurement",
'device_class': 'current',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_CURRENT,
'unique_id':'sems_grid_current_sensor',
'device': create_device(data['type'])
}
Expand All @@ -297,7 +305,7 @@ def create_device(model):
'value_template':'{{ value_json.grid_frequency }}',
'icon':'mdi:current-ac',
'state_topic':'sems/sensors',
'state_class': "measurement",
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': None,
'unique_id':'sems_grid_frequency_sensor',
'device': create_device(data['type'])
Expand All @@ -308,8 +316,8 @@ def create_device(model):
'value_template':'{{ value_json.dc_voltage_str_1 }}',
'icon':'mdi:current-dc',
'state_topic':'sems/sensors',
'state_class': "measurement",
'device_class': 'voltage',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_VOLTAGE,
'unique_id':'sems_str_1_voltage_sensor',
'device': create_device(data['type'])
}
Expand All @@ -319,8 +327,8 @@ def create_device(model):
'value_template':'{{ value_json.dc_current_str_1 }}',
'icon':'mdi:current-dc',
'state_topic':'sems/sensors',
'state_class': "measurement",
'device_class': 'current',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_CURRENT,
'unique_id':'sems_str_1_current_sensor',
'device': create_device(data['type'])
}
Expand All @@ -330,8 +338,8 @@ def create_device(model):
'value_template':'{{ value_json.dc_voltage_str_2 }}',
'icon':'mdi:current-dc',
'state_topic':'sems/sensors',
'state_class': "measurement",
'device_class': 'voltage',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_VOLTAGE,
'unique_id':'sems_str_2_voltage_sensor',
'device': create_device(data['type'])
}
Expand All @@ -341,8 +349,8 @@ def create_device(model):
'value_template':'{{ value_json.dc_current_str_2 }}',
'icon':'mdi:current-dc',
'state_topic':'sems/sensors',
'state_class': "measurement",
'device_class': 'current',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_CURRENT,
'unique_id':'sems_str_2_current_sensor',
'device': create_device(data['type'])
}
Expand All @@ -352,8 +360,8 @@ def create_device(model):
'value_template':'{{ value_json.battery_soc }}',
'icon':'mdi:battery-charging',
'state_topic':'sems/sensors',
'state_class': "measurement",
'device_class': None,
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_BATTERY,
'unique_id':'sems_battery_soc_sensor',
'device': create_device(data['type'])
}
Expand All @@ -363,7 +371,7 @@ def create_device(model):
'value_template':'{{ value_json.battery_soh }}',
'icon':'mdi:medical-bag',
'state_topic':'sems/sensors',
'state_class': "measurement",
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': None,
'unique_id':'sems_battery_soh_sensor',
'device': create_device(data['type'])
Expand Down

0 comments on commit 8f761af

Please sign in to comment.