From dbb79a0ecf5c2a3b9ae6aff89691dbfc50f342d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel?= <miguel.angel.lopez.vicente@gmail.com>
Date: Tue, 11 Apr 2023 15:16:36 +0200
Subject: [PATCH] Borrado

---
 customs_components/tarifa_20td/__init__.py    |  31 ----
 customs_components/tarifa_20td/config_flow.py | 112 -----------
 customs_components/tarifa_20td/const.py       |   8 -
 customs_components/tarifa_20td/manifest.json  |  14 --
 customs_components/tarifa_20td/sensor.py      | 175 ------------------
 customs_components/tarifa_20td/strings.json   |  21 ---
 .../tarifa_20td/translations/en.json          |  37 ----
 7 files changed, 398 deletions(-)
 delete mode 100644 customs_components/tarifa_20td/__init__.py
 delete mode 100644 customs_components/tarifa_20td/config_flow.py
 delete mode 100644 customs_components/tarifa_20td/const.py
 delete mode 100644 customs_components/tarifa_20td/manifest.json
 delete mode 100644 customs_components/tarifa_20td/sensor.py
 delete mode 100644 customs_components/tarifa_20td/strings.json
 delete mode 100644 customs_components/tarifa_20td/translations/en.json

diff --git a/customs_components/tarifa_20td/__init__.py b/customs_components/tarifa_20td/__init__.py
deleted file mode 100644
index df091a9..0000000
--- a/customs_components/tarifa_20td/__init__.py
+++ /dev/null
@@ -1,31 +0,0 @@
-"""Balance Neto"""
-from __future__ import annotations
-
-from homeassistant.config_entries import ConfigEntry
-from homeassistant.const import Platform
-from homeassistant.core import HomeAssistant
-
-from .const import DOMAIN
-
-PLATFORMS: list[Platform] = [Platform.SENSOR]
-
-
-async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
-    await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
-
-    entry.async_on_unload(entry.add_update_listener(_async_update_options))
-    return True
-
-
-async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
-    """Unload a config entry."""
-    return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
-
-
-async def _async_update_options(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
-    """Handle options update."""
-    # update entry replacing data with new options
-    hass.config_entries.async_update_entry(
-        config_entry, data={**config_entry.data, **config_entry.options}
-    )
-    await hass.config_entries.async_reload(config_entry.entry_id)
diff --git a/customs_components/tarifa_20td/config_flow.py b/customs_components/tarifa_20td/config_flow.py
deleted file mode 100644
index 57c9c93..0000000
--- a/customs_components/tarifa_20td/config_flow.py
+++ /dev/null
@@ -1,112 +0,0 @@
-from __future__ import annotations
-
-import logging
-from typing import Any
-
-import voluptuous as vol
-from homeassistant.core import callback
-
-from homeassistant import config_entries
-from homeassistant.data_entry_flow import FlowResult
-from homeassistant.helpers.selector import (
-    NumberSelector,
-    NumberSelectorMode,
-    NumberSelectorConfig,
-)
-
-from .const import *
-
-_LOGGER = logging.getLogger(__name__)
-
-SCHEMA = vol.Schema(
-    {
-        vol.Required(CONF_VALLE): NumberSelector(
-            NumberSelectorConfig(min=0, max=1, step="any", unit_of_measurement="€/kWh", mode=NumberSelectorMode.BOX)
-        ),
-        vol.Required(CONF_LLANA): NumberSelector(
-            NumberSelectorConfig(min=0, max=1, step="any", unit_of_measurement="€/kWh", mode=NumberSelectorMode.BOX)
-        ),
-        vol.Required(CONF_PUNTA): NumberSelector(
-            NumberSelectorConfig(min=0, max=1, step="any", unit_of_measurement="€/kWh", mode=NumberSelectorMode.BOX)
-        ),
-        vol.Required(CONF_DIA): NumberSelector(
-            NumberSelectorConfig(min=0, max=3, step="any", unit_of_measurement="€/dia", mode=NumberSelectorMode.BOX)
-        )
-    }
-)
-
-
-class PlaceholderHub:
-    def __init__(self, precio_valle: float, precio_llana: float, precio_punta: float, coste_dia: float) -> None:
-        """Initialize."""
-        self.precio_valle = precio_valle
-        self.precio_llana = precio_llana
-        self.precio_punta = precio_punta
-        self.coste_dia = coste_dia
-
-
-class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
-    VERSION = 1
-
-    @staticmethod
-    @callback
-    def async_get_options_flow(config_entry):
-        return OptionFlowHandler(config_entry)
-
-    async def async_step_user(
-            self, user_input: dict[str, Any] | None = None
-    ) -> FlowResult:
-        """Handle the initial step."""
-        if user_input is None:
-            return self.async_show_form(
-                step_id="user", data_schema=SCHEMA
-            )
-        else:
-            return self.async_create_entry(title="Tarifa 2.0 TD", data=user_input)
-
-
-class OptionFlowHandler(config_entries.OptionsFlow):
-    def __init__(self, config_entry):
-        self.config_entry = config_entry
-
-    async def async_step_init(self, user_input=None):
-        """Manage the options."""
-        if user_input is not None:
-            return self.async_create_entry(title="Tarifa 2.0 TD", data=user_input)
-
-        # Fill options with entry data
-        valle = self.config_entry.options.get(
-            CONF_VALLE, self.config_entry.data[CONF_VALLE]
-        )
-        llana = self.config_entry.options.get(
-            CONF_LLANA, self.config_entry.data[CONF_LLANA]
-        )
-        punta = self.config_entry.options.get(
-            CONF_PUNTA, self.config_entry.data[CONF_PUNTA]
-        )
-        dia = self.config_entry.options.get(
-            CONF_DIA, self.config_entry.data[CONF_DIA]
-        )
-
-        schema = vol.Schema(
-            {
-                vol.Required(CONF_VALLE, default=float(valle)): NumberSelector(
-                    NumberSelectorConfig(min=0, max=1, step="any", unit_of_measurement="€/kWh",
-                                         mode=NumberSelectorMode.BOX)
-                ),
-                vol.Required(CONF_LLANA, default=float(llana)): NumberSelector(
-                    NumberSelectorConfig(min=0, max=1, step="any", unit_of_measurement="€/kWh",
-                                         mode=NumberSelectorMode.BOX)
-                ),
-                vol.Required(CONF_PUNTA, default=float(punta)): NumberSelector(
-                    NumberSelectorConfig(min=0, max=1, step="any", unit_of_measurement="€/kWh",
-                                         mode=NumberSelectorMode.BOX)
-                ),
-                vol.Required(CONF_DIA, default=float(dia)): NumberSelector(
-                    NumberSelectorConfig(min=0, max=3, step="any", unit_of_measurement="€/dia",
-                                         mode=NumberSelectorMode.BOX)
-                )
-            }
-        )
-
-        return self.async_show_form(step_id="init", data_schema=schema)
diff --git a/customs_components/tarifa_20td/const.py b/customs_components/tarifa_20td/const.py
deleted file mode 100644
index a8ddb62..0000000
--- a/customs_components/tarifa_20td/const.py
+++ /dev/null
@@ -1,8 +0,0 @@
-"""Constants for Tarifa 2.0 TD."""
-
-DOMAIN = "tarifa_20td"
-
-CONF_VALLE = 'precio_valle'
-CONF_LLANA = 'precio_llana'
-CONF_PUNTA = 'precio_punta'
-CONF_DIA = 'coste_dia'
\ No newline at end of file
diff --git a/customs_components/tarifa_20td/manifest.json b/customs_components/tarifa_20td/manifest.json
deleted file mode 100644
index 3face10..0000000
--- a/customs_components/tarifa_20td/manifest.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-  "domain": "tarifa_20td",
-  "name": "Tarifa 2.0 TD",
-  "codeowners": [
-    "@miguelangellv"
-  ],
-  "config_flow": true,
-  "documentation": "https://github.com/MiguelAngelLV/tarifa_20td",
-  "iot_class": "local_polling",
-  "issue_tracker": "https://github.com/MiguelAngelLV/tarifa_20td/issues",
-  "requirements": ["holidays==0.18.0"],
-  "version": "0.1.0"
-
-}
diff --git a/customs_components/tarifa_20td/sensor.py b/customs_components/tarifa_20td/sensor.py
deleted file mode 100644
index 5764562..0000000
--- a/customs_components/tarifa_20td/sensor.py
+++ /dev/null
@@ -1,175 +0,0 @@
-import asyncio
-from datetime import datetime
-from typing import Mapping, Any
-from datetime import datetime, timedelta
-
-import holidays
-
-from homeassistant.components.sensor import (
-    SensorEntity,
-    SensorEntityDescription,
-    DEVICE_CLASS_MONETARY,
-    STATE_CLASS_TOTAL_INCREASING,
-    DEVICE_CLASS_ENERGY,
-    RestoreEntity
-)
-from homeassistant.config_entries import ConfigEntry
-from homeassistant.core import HomeAssistant
-from homeassistant.helpers.entity_platform import AddEntitiesCallback
-from homeassistant.helpers.typing import StateType
-from homeassistant.helpers.event import async_track_point_in_time
-
-PRICE_DESCRIPTION = SensorEntityDescription(
-    key="precio_20td",
-    icon="mdi:currency-eur",
-    name="Precio kWh",
-    device_class=DEVICE_CLASS_MONETARY,
-    native_unit_of_measurement="€/kWh"
-)
-
-FIXED_DESCRIPTION = SensorEntityDescription(
-    key="coste_fijo_20td",
-    icon="mdi:currency-eur",
-    name="Costes Fijos Totales",
-    state_class=STATE_CLASS_TOTAL_INCREASING,
-    native_unit_of_measurement="€"
-)
-
-DUMMY_DESCRIPTION = SensorEntityDescription(
-    key="coste_fijo_kwh",
-    icon="mdi:currency-eur",
-    name="Costes Fijos",
-    device_class=DEVICE_CLASS_ENERGY,
-    state_class=STATE_CLASS_TOTAL_INCREASING,
-    native_unit_of_measurement="kWh"
-)
-
-
-async def async_setup_entry(
-        hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
-) -> None:
-    valle = float(entry.data['precio_valle'])
-    llana = float(entry.data['precio_llana'])
-    punta = float(entry.data['precio_punta'])
-    coste_dia = float(entry.data['coste_dia'])
-
-    price_sensor = PriceSensor(PRICE_DESCRIPTION, valle, llana, punta, hass)
-    fixed_sensor = FixedSensor(FIXED_DESCRIPTION, coste_dia, hass)
-    dummy_sensor = DummySensor(DUMMY_DESCRIPTION)
-    async_add_entities([price_sensor, fixed_sensor, dummy_sensor])
-
-
-class PriceSensor(SensorEntity):
-
-    def __init__(self, description: SensorEntityDescription, valle: float, llana: float, punta: float, hass) -> None:
-        super().__init__()
-        self._state = None
-        self._attrs: Mapping[str, Any] = {}
-        self._attr_name = description.name
-        self._attr_unique_id = description.key
-        self.entity_description = description
-        self._valle = valle
-        self._llana = llana
-        self._punta = punta
-        self._holidays = holidays.ES()
-
-        async def update_price_and_schedule(now):
-            self.update_price()
-            next = now + timedelta(hours=1)
-            async_track_point_in_time(hass, update_price_and_schedule, next)
-
-        now = datetime.now()
-        next = now.replace(minute=0, second=0) + timedelta(hours=1)
-        async_track_point_in_time(hass, update_price_and_schedule, next)
-
-    @property
-    def native_value(self) -> StateType:
-        return self._state
-
-    async def async_added_to_hass(self) -> None:
-        self.update_price()
-
-
-    @property
-    def should_poll(self):
-        return False
-
-    def update_price(self):
-        now = datetime.now()
-
-        if now in self._holidays or 5 <= now.weekday() <= 6:
-            self._state = self._valle
-        else:
-            hour = now.hour
-            if hour < 8:
-                self._state = self._valle
-            elif hour < 10:
-                self._state = self._llana
-            elif hour < 14:
-                self._state = self._punta
-            elif hour < 18:
-                self._state = self._llana
-            elif hour < 22:
-                self._state = self._punta
-            else:
-                self._state = self._llana
-
-        self.async_write_ha_state()
-
-
-class FixedSensor(SensorEntity, RestoreEntity):
-
-    def __init__(self, description: SensorEntityDescription, coste_dia, hass) -> None:
-        super().__init__()
-        self._state = 0
-        self._attrs: Mapping[str, Any] = {}
-        self._attr_name = description.name
-        self._attr_unique_id = description.key
-        self.entity_description = description
-        self._coste_dia = coste_dia
-
-        async def update_cost_and_schedule(now):
-            self.update_price()
-            next = now + timedelta(days=1)
-            async_track_point_in_time(hass, update_cost_and_schedule, next)
-
-        now = datetime.now()
-        next = now.replace(hour=0, minute=5, second=0) + timedelta(days=1)
-        async_track_point_in_time(hass, update_cost_and_schedule, next)
-
-    @property
-    def native_value(self) -> StateType:
-        return self._state
-
-    async def async_added_to_hass(self) -> None:
-        await super().async_added_to_hass()
-        if (last_sensor_data := await self.async_get_last_state()) is not None:
-            self._state = last_sensor_data.state
-            self.async_write_ha_state()
-
-    @property
-    def should_poll(self):
-        return False
-
-    def update_price(self):
-        self._state = float(self._state) + self._coste_dia
-        self.async_write_ha_state()
-
-
-
-class DummySensor(SensorEntity):
-
-    def __init__(self, description: SensorEntityDescription) -> None:
-        super().__init__()
-        self._state = 0
-        self._attrs: Mapping[str, Any] = {}
-        self._attr_name = description.name
-        self._attr_unique_id = description.key
-        self.entity_description = description
-
-    @property
-    def native_value(self) -> StateType:
-        return self._state
-
-    async def async_added_to_hass(self) -> None:
-        self.async_write_ha_state()
diff --git a/customs_components/tarifa_20td/strings.json b/customs_components/tarifa_20td/strings.json
deleted file mode 100644
index d6e3212..0000000
--- a/customs_components/tarifa_20td/strings.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
-  "config": {
-    "step": {
-      "user": {
-        "data": {
-          "host": "[%key:common::config_flow::data::host%]",
-          "username": "[%key:common::config_flow::data::username%]",
-          "password": "[%key:common::config_flow::data::password%]"
-        }
-      }
-    },
-    "error": {
-      "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
-      "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
-      "unknown": "[%key:common::config_flow::error::unknown%]"
-    },
-    "abort": {
-      "already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
-    }
-  }
-}
diff --git a/customs_components/tarifa_20td/translations/en.json b/customs_components/tarifa_20td/translations/en.json
deleted file mode 100644
index a500de9..0000000
--- a/customs_components/tarifa_20td/translations/en.json
+++ /dev/null
@@ -1,37 +0,0 @@
-{
-  "config": {
-    "abort": {
-      "already_configured": "Device is already configured"
-    },
-    "error": {
-      "cannot_connect": "Failed to connect",
-      "invalid_auth": "Invalid authentication",
-      "unknown": "Unexpected error"
-    },
-    "step": {
-      "user": {
-        "title": "Tarifa 2.0 TD",
-        "data": {
-          "precio_llana": "Precio horas llanas",
-          "precio_valle": "Precio en horas valle",
-          "precio_punta": "Precio en horas punta",
-          "coste_dia": "Precio de costes fijos por día"
-        }
-      }
-    }
-  },
-
-  "options": {
-    "step": {
-      "init": {
-        "title": "Actualizar precios.",
-        "data": {
-          "precio_llana": "Precio horas llanas",
-          "precio_valle": "Precio en horas valle",
-          "precio_punta": "Precio en horas punta",
-          "coste_dia": "Precio de costes fijos por día"
-        }
-      }
-    }
-  }
-}
\ No newline at end of file