Skip to content

Commit

Permalink
Merge pull request #188 from henricm/new-entity-naming-style
Browse files Browse the repository at this point in the history
feat: migrate to new entity naming style
  • Loading branch information
argoyle authored Aug 8, 2022
2 parents 4110516 + b801eb6 commit 8560efb
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 88 deletions.
91 changes: 47 additions & 44 deletions custom_components/ferroamp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def sso_event_received(msg):
if new:
sensors = sso_sensors[sso_id] = [
VoltageFerroampSensor(
f"{device_name} PV String Voltage",
slug,
"PV String Voltage",
device_id,
"upv",
"mdi:current-dc",
device_id,
Expand All @@ -173,8 +173,8 @@ def sso_event_received(msg):
model=model
),
CurrentFerroampSensor(
f"{device_name} PV String Current",
slug,
"PV String Current",
device_id,
"ipv",
"mdi:current-dc",
device_id,
Expand All @@ -185,8 +185,8 @@ def sso_event_received(msg):
model=model
),
CalculatedPowerFerroampSensor(
f"{device_name} PV String Power",
slug,
"PV String Power",
device_id,
"upv",
"ipv",
"mdi:solar-power",
Expand All @@ -197,8 +197,8 @@ def sso_event_received(msg):
model=model
),
EnergyFerroampSensor(
f"{device_name} Total Energy",
slug,
"Total Energy",
device_id,
"wpv",
"mdi:solar-power",
device_id,
Expand All @@ -210,8 +210,8 @@ def sso_event_received(msg):
state_class=SensorStateClass.TOTAL_INCREASING
),
FaultcodeFerroampSensor(
f"{device_name} Faultcode",
slug,
"Faultcode",
device_id,
"faultcode",
device_id,
device_name,
Expand All @@ -221,8 +221,8 @@ def sso_event_received(msg):
model=model
),
RelayStatusFerroampSensor(
f"{device_name} Relay Status",
slug,
"Relay Status",
device_id,
"relaystatus",
device_id,
device_name,
Expand All @@ -231,8 +231,8 @@ def sso_event_received(msg):
model=model
),
TemperatureFerroampSensor(
f"{device_name} PCB Temperature",
slug,
"PCB Temperature",
device_id,
"temp",
device_id,
device_name,
Expand All @@ -258,8 +258,8 @@ def eso_event_received(msg):
if new:
sensors = eso_sensors[eso_id] = [
VoltageFerroampSensor(
f"{device_name} Battery Voltage",
slug,
"Battery Voltage",
device_id,
"ubat",
"mdi:battery",
device_id,
Expand All @@ -269,8 +269,8 @@ def eso_event_received(msg):
config_id,
),
CurrentFerroampSensor(
f"{device_name} Battery Current",
slug,
"Battery Current",
device_id,
"ibat",
"mdi:battery",
device_id,
Expand All @@ -280,8 +280,8 @@ def eso_event_received(msg):
config_id
),
CalculatedPowerFerroampSensor(
f"{device_name} Battery Power",
slug,
"Battery Power",
device_id,
"ubat",
"ibat",
"mdi:battery",
Expand All @@ -291,8 +291,8 @@ def eso_event_received(msg):
config_id,
),
EnergyFerroampSensor(
f"{device_name} Total Energy Produced",
slug,
"Total Energy Produced",
device_id,
"wbatprod",
"mdi:battery-plus",
device_id,
Expand All @@ -303,8 +303,8 @@ def eso_event_received(msg):
state_class=SensorStateClass.TOTAL_INCREASING,
),
EnergyFerroampSensor(
f"{device_name} Total Energy Consumed",
slug,
"Total Energy Consumed",
device_id,
"wbatcons",
"mdi:battery-minus",
device_id,
Expand All @@ -315,8 +315,8 @@ def eso_event_received(msg):
state_class=SensorStateClass.TOTAL_INCREASING,
),
BatteryFerroampSensor(
f"{device_name} State of Charge",
slug,
"State of Charge",
device_id,
"soc",
device_id,
device_name,
Expand All @@ -325,8 +325,8 @@ def eso_event_received(msg):
config_id,
),
FaultcodeFerroampSensor(
f"{device_name} Faultcode",
slug,
"Faultcode",
device_id,
"faultcode",
device_id,
device_name,
Expand All @@ -335,17 +335,17 @@ def eso_event_received(msg):
config_id,
),
RelayStatusFerroampSensor(
f"{device_name} Relay Status",
slug,
"Relay Status",
device_id,
"relaystatus",
device_id,
device_name,
interval,
config_id,
),
TemperatureFerroampSensor(
f"{device_name} PCB Temperature",
slug,
"PCB Temperature",
device_id,
"temp",
device_id,
device_name,
Expand All @@ -362,6 +362,8 @@ def esm_event_received(msg):
event = json.loads(msg.payload)
esm_id = event["id"]["val"]
model = None
device_id = f"{slug}_esm_{esm_id}"
device_name = f"ESM {esm_id}"
match = REGEX_ESM_ID.match(esm_id)
if match is not None and match.group(2) is not None and match.group(1) is not None:
migrate_entities(
Expand All @@ -374,15 +376,15 @@ def esm_event_received(msg):
)
esm_id = match.group(2)
model = match.group(1)
device_id = f"{slug}_esm_{esm_id}"
device_name = f"ESM {esm_id}"
device_id = f"{slug}_esm_{esm_id}"
device_name = f"ESM {esm_id}"
store, new = get_store(device_id)
sensors = esm_sensors.get(esm_id)
if new:
sensors = esm_sensors[esm_id] = [
StringValFerroampSensor(
f"{device_name} Status",
slug,
"Status",
device_id,
"status",
"",
"mdi:traffic-light",
Expand All @@ -393,8 +395,8 @@ def esm_event_received(msg):
model=model
),
PercentageFerroampSensor(
f"{device_name} State of Health",
slug,
"State of Health",
device_id,
"soh",
device_id,
device_name,
Expand All @@ -404,8 +406,8 @@ def esm_event_received(msg):
model=model
),
BatteryFerroampSensor(
f"{device_name} State of Charge",
slug,
"State of Charge",
device_id,
"soc",
device_id,
device_name,
Expand All @@ -415,8 +417,8 @@ def esm_event_received(msg):
model=model
),
IntValFerroampSensor(
f"{device_name} Rated Capacity",
slug,
"Rated Capacity",
device_id,
"ratedCapacity",
ENERGY_WATT_HOUR,
"mdi:battery",
Expand All @@ -427,8 +429,8 @@ def esm_event_received(msg):
model=model
),
PowerFerroampSensor(
f"{device_name} Rated Power",
slug,
"Rated Power",
device_id,
"ratedPower",
"mdi:battery",
device_id,
Expand Down Expand Up @@ -564,6 +566,7 @@ class FerroampSensor(SensorEntity, RestoreEntity):
def __init__(self, name, entity_prefix, unit: str | None, icon, device_id, device_name, interval, config_id, **kwargs):
"""Initialize the sensor."""
self._attr_name = name
self._attr_has_entity_name = True
self._attr_unit_of_measurement = unit
self._attr_native_unit_of_measurement = unit
self._attr_icon = icon
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "Ferroamp Sensors",
"homeassistant": "2021.12.0b1"
"homeassistant": "2022.8.0b0"
}
3 changes: 1 addition & 2 deletions requirements.test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Strictly for tests
# TODO: Replace master-branch version when a new release is available
pytest-homeassistant-custom-component==0.9.4
pytest-homeassistant-custom-component==0.10.2
# From our manifest.json for our custom component
aiohttp_cors==0.7.0
paho-mqtt==1.6.1
Loading

0 comments on commit 8560efb

Please sign in to comment.