diff --git a/custom_components/barry/pybarry.py b/custom_components/barry/pybarry.py index 24dd2f3..d4b330f 100644 --- a/custom_components/barry/pybarry.py +++ b/custom_components/barry/pybarry.py @@ -31,8 +31,7 @@ def __init__( @staticmethod def hour_rounder(t): # Rounds to nearest hour by adding a timedelta hour if minute >= 30 - return (t.replace(second=0, microsecond=0, minute=0, hour=t.hour) - + timedelta(hours=t.minute // 30)) + return (t.replace(second=0, microsecond=0, minute=0, hour=t.hour)) @staticmethod def get_currency(data): @@ -65,11 +64,11 @@ def get_current_co2_emission(self, price_code): def get_current_spot_price(self, price_code): current_time = self.hour_rounder( datetime.utcnow().replace(microsecond=0)).isoformat() + 'Z' - last_hour_date_time = self.hour_rounder( - (datetime.utcnow() - timedelta(hours=1)).replace(microsecond=0)).isoformat() + 'Z' + next_hour_date_time = self.hour_rounder( + (datetime.utcnow() + timedelta(hours=1)).replace(microsecond=0)).isoformat() + 'Z' data = '{ "jsonrpc": "2.0", "id": 0, "method": "co.getbarry.api.v1.OpenApiController.getPrice", "params": [ "%s", "%s", "%s" ] }' % ( - price_code, last_hour_date_time, current_time) + price_code, current_time, next_hour_date_time) response = requests.post( self.endpoint, headers=self.headers, data=data) json_res = response.json() @@ -85,11 +84,11 @@ def get_current_spot_price(self, price_code): def get_current_total_price(self, mpid): current_time = self.hour_rounder( datetime.utcnow().replace(microsecond=0)).isoformat() + 'Z' - last_hour_date_time = self.hour_rounder( - (datetime.utcnow() - timedelta(hours=1)).replace(microsecond=0)).isoformat() + 'Z' + next_hour_date_time = self.hour_rounder( + (datetime.utcnow() + timedelta(hours=1)).replace(microsecond=0)).isoformat() + 'Z' data = '{ "jsonrpc": "2.0", "id": 0, "method": "co.getbarry.api.v1.OpenApiController.getTotalKwHPrice", "params": [ "%s", "%s", "%s" ] }' % ( - mpid, last_hour_date_time, current_time) + mpid, current_time, next_hour_date_time) response = requests.post( self.endpoint, headers=self.headers, data=data) json_res = response.json() diff --git a/custom_components/barry/sensor.py b/custom_components/barry/sensor.py index b989336..62d239d 100644 --- a/custom_components/barry/sensor.py +++ b/custom_components/barry/sensor.py @@ -104,10 +104,6 @@ def unique_id(self): def state(self) -> float: return self.current_total_price - @property - def icon(self) -> str: - return "mdi:flash" - @property def unit(self) -> str: return self._price_type @@ -159,6 +155,10 @@ def today(self) -> list: def today(self) -> list: return self._tomorrow + @property + def device_class(self) -> str: + return "monetary" + def _update_current_price(self) -> None: _LOGGER.debug("Updating current price") _LOGGER.debug("barry_home: %s", self._barry_home)