Skip to content

Commit

Permalink
Add run percentage back + small changes
Browse files Browse the repository at this point in the history
Add run percentage back + small changes
  • Loading branch information
jobvk committed Aug 22, 2022
2 parents d906e7e + eaf36a4 commit 056eea3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Windcentrale app
## Contributors
Special Thanks to all contributors
* [@vdheidenet](https://github.com/vdheidenet): Sharing his data for creating the signing in function
* [@rob-on-git](https://github.com/rob-on-git): For creating a formula for the run percentage sensor

## License
[Apache License 2.0](https://github.com/jobvk/Home-Assistant-Windcentrale/blob/main/LICENSE)
Expand Down
1 change: 1 addition & 0 deletions custom_components/windcentrale/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"yearproduction": ["Production This Year", SensorDeviceClass.ENERGY, ENERGY_KILO_WATT_HOUR, None, "year_production"],
"runtimeyear": ["Hours Run This Year", None, TIME_HOURS, "mdi:calendar-clock", "year_runtime"],
"runtimetotal": ["Hours Run Total", None, TIME_HOURS, "mdi:calendar-clock", "total_runtime"],
"runpercentage": ["Run Percentage", None, PERCENTAGE, "mdi:percent", "year_runtime"],
"timestamp": ["Last Update", SensorDeviceClass.TIMESTAMP, None, None, "timestamp"]
}

Expand Down
2 changes: 1 addition & 1 deletion custom_components/windcentrale/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"iot_class": "cloud_polling",
"dependencies": [],
"codeowners": ["@jobvk"],
"version": "0.2.0",
"version": "0.2.1",
"loggers": ["boto3"]
}
5 changes: 4 additions & 1 deletion custom_components/windcentrale/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ATTR_LAST_RESET,
CONF_STATE_CLASS,
)

async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add sensors for passed config_entry in HA."""
wind = hass.data[DOMAIN][config_entry.entry_id]
Expand Down Expand Up @@ -135,7 +136,7 @@ def extra_state_attributes(self):
elif self.type == "windspeed" or self.type == "powertotal" or self.type == "powerpershare" or self.type == "powerpercentage" or self.type == "rpm":
attr[CONF_STATE_CLASS] = SensorStateClass.MEASUREMENT
elif self.type == "energy" or self.type == "yearproduction":
attr[ATTR_LAST_RESET] = datetime(datetime.today().year, 1 ,1)
attr[ATTR_LAST_RESET] = datetime(datetime.now().year, 1, 1)
attr[CONF_STATE_CLASS] = SensorStateClass.TOTAL
return attr

Expand All @@ -154,6 +155,8 @@ def update(self):
self._state = self._windturbine.live_data[self._sensor] * self._windturbine.shares
elif self.type == "energy":
self._state = self._windturbine.live_data[self._sensor] / self._windturbine.total_shares * self._windturbine.shares
elif self.type == "runpercentage":
self._state = round(timedelta(hours=self._windturbine.live_data[self._sensor]) / (datetime.now() - datetime(datetime.now().year, 1, 1)) * 100, 2)
else:
self._state = self._windturbine.live_data[self._sensor]

Expand Down
4 changes: 2 additions & 2 deletions custom_components/windcentrale/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"title": "The Windcentrale Set Up",
"description": "Set up the Windcentrale integration. https://www.windcentrale.nl\n\nIf you need help with the configuration have a look over here: https://github.com/jobvk/Home-Assistant-Windcentrale\n\nFill in the amount of windshares you own off the specific wind turbine:",
"data": {
"email": "Enter your e-mail address",
"password": "Enter your password"
"email": "Enter your email address",
"password": "Enter your password"
}
}
},
Expand Down
4 changes: 1 addition & 3 deletions custom_components/windcentrale/wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ async def update(self):
for key, value in json_items[self.windturbine_id].items():
if key == "wind_power" or key == "power" or key == "power_per_share" or key == "power_percentage" or key == "year_production" or key == "total_runtime":
self.response_data[key] = int(value)
elif key == "rpm":
elif key == "rpm" or key == "year_runtime":
self.response_data[key] = float(value)
elif key == "year_runtime":
self.response_data[key] = round(float(value), 2)
elif key == "timestamp":
self.response_data[key] = datetime.datetime.fromtimestamp(int(value))
elif key == "pulsating":
Expand Down

0 comments on commit 056eea3

Please sign in to comment.