Skip to content

Commit

Permalink
go to v7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jugla authored and github-actions[bot] committed Oct 30, 2021
1 parent e822ec8 commit f0aa67c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
23 changes: 11 additions & 12 deletions custom_components/worldtidesinfocustom/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
CONF_SHOW_ON_MAP,
CONF_SOURCE,
)
from homeassistant.helpers.entity_registry import async_get_registry
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
from homeassistant.helpers.entity_registry import async_get_registry



# Component Library
from . import give_persistent_filename
Expand Down Expand Up @@ -211,24 +209,25 @@ async def async_added_to_hass(self):
"""Handle added to Hass."""
await super().async_added_to_hass()


entity_id_main_sensor = None

#Fetch the name of sensor
# Fetch the name of sensor
registry = await async_get_registry(self.hass)
entity_id_main_sensor = registry.async_get_entity_id("sensor",DOMAIN,self._unique_id + SENSOR_NEXT_TIDE_SUFFIX)
_LOGGER.debug("Camera: entity main sensor %s",entity_id_main_sensor)
entity_id_main_sensor = registry.async_get_entity_id(
"sensor", DOMAIN, self._unique_id + SENSOR_NEXT_TIDE_SUFFIX
)
_LOGGER.debug("Camera: entity main sensor %s", entity_id_main_sensor)

if entity_id_main_sensor == None:
entity_id_main_sensor = "sensor." + self._name + SENSOR_NEXT_TIDE_SUFFIX
entity_id_main_sensor = "sensor." + self._name + SENSOR_NEXT_TIDE_SUFFIX

async_track_state_change_event(
self._hass,
[entity_id_main_sensor],
self._async_worldtidesinfo_follower_sensor_state_listener,
)

_LOGGER.debug("Camera: listen main sensor %s",entity_id_main_sensor)
_LOGGER.debug("Camera: listen main sensor %s", entity_id_main_sensor)
# pure async i.e. wait for update of main sensor
# no need to call self.schedule_update_ha_state
# be robust to be sure to be update
Expand All @@ -239,7 +238,9 @@ def _get_image(self):
current_time = time.time()
read_ok = False
read_image = None
_LOGGER.debug("Camera: Sync Fetch new picture image from %s", self._image_filename)
_LOGGER.debug(
"Camera: Sync Fetch new picture image from %s", self._image_filename
)
"""Return image response."""
try:
with open(self._image_filename, "rb") as file:
Expand All @@ -256,7 +257,6 @@ def _get_image(self):
self._last_requested_date = current_time
self._generated_at = time.ctime(os.path.getmtime(self._image_filename))


def camera_image(self):
"""Return image response."""
_LOGGER.debug("Camera : Sync Image Tides sensor %s", self._name)
Expand All @@ -267,7 +267,6 @@ async def async_camera_image(self):
_LOGGER.debug("Camera : Async Image Tides sensor %s", self._name)
return self._image


def update(self):
"""Read the contents of the file."""
self._get_image()
Expand Down
19 changes: 14 additions & 5 deletions custom_components/worldtidesinfocustom/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,22 @@ async def async_step_init(self, user_input=None):
default=self.config_entry.options.get(CONF_SHOW_ON_MAP),
): bool,
vol.Optional(
CONF_STATION_DISTANCE, default=self.config_entry.options.get(CONF_STATION_DISTANCE,
self.config_entry.data.get(CONF_STATION_DISTANCE,DEFAULT_STATION_DISTANCE))
CONF_STATION_DISTANCE,
default=self.config_entry.options.get(
CONF_STATION_DISTANCE,
self.config_entry.data.get(
CONF_STATION_DISTANCE, DEFAULT_STATION_DISTANCE
),
),
): cv.positive_int,
vol.Optional(
CONF_PLOT_COLOR, default=self.config_entry.options.get(CONF_PLOT_COLOR,
self.config_entry.data.get(CONF_PLOT_COLOR,
DEFAULT_PLOT_COLOR))
CONF_PLOT_COLOR,
default=self.config_entry.options.get(
CONF_PLOT_COLOR,
self.config_entry.data.get(
CONF_PLOT_COLOR, DEFAULT_PLOT_COLOR
),
),
): cv.string,
}
),
Expand Down
2 changes: 1 addition & 1 deletion custom_components/worldtidesinfocustom/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "worldtidesinfocustom",
"name": "WorldTidesInfoCustom",
"version" : "6.4.0",
"version" : "7.0.0",
"codeowners": ["@jugla"],
"documentation": "https://github.com/jugla/worldtidesinfocustom",
"issue_tracker": "https://github.com/jugla/worldtidesinfocustom/issues",
Expand Down
23 changes: 10 additions & 13 deletions custom_components/worldtidesinfocustom/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
STATE_UNKNOWN,
)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_registry import async_get_registry

# HA library
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
from homeassistant.helpers.entity_registry import async_get_registry


# Component Library
from . import give_persistent_filename, worldtidesinfo_data_coordinator
Expand Down Expand Up @@ -419,14 +418,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
vertical_ref = config.get(CONF_VERTICAL_REF)
plot_color = config.get(CONF_PLOT_COLOR)
if config_entry.options.get(CONF_PLOT_COLOR):
plot_color = config_entry.options.get(CONF_PLOT_COLOR)
plot_color = config_entry.options.get(CONF_PLOT_COLOR)

plot_background = config.get(CONF_PLOT_BACKGROUND)

tide_station_distance = config.get(CONF_STATION_DISTANCE)
if config_entry.options.get(CONF_STATION_DISTANCE):
tide_station_distance = config_entry.options.get(CONF_STATION_DISTANCE)

tide_station_distance = config_entry.options.get(CONF_STATION_DISTANCE)

# what is the unit used
if config.get(CONF_UNIT) == HA_CONF_UNIT and hass.config.units == IMPERIAL_SYSTEM:
Expand Down Expand Up @@ -559,14 +557,15 @@ async def async_added_to_hass(self):

entity_id_main_sensor = None

#Fetch the name of sensor
# Fetch the name of sensor
registry = await async_get_registry(self.hass)
entity_id_main_sensor = registry.async_get_entity_id("sensor",DOMAIN,self._unique_id + SENSOR_NEXT_TIDE_SUFFIX)
_LOGGER.debug("Sensor: entity main sensor %s",entity_id_main_sensor)
entity_id_main_sensor = registry.async_get_entity_id(
"sensor", DOMAIN, self._unique_id + SENSOR_NEXT_TIDE_SUFFIX
)
_LOGGER.debug("Sensor: entity main sensor %s", entity_id_main_sensor)

if entity_id_main_sensor == None:
entity_id_main_sensor = "sensor." + self._name + SENSOR_NEXT_TIDE_SUFFIX

entity_id_main_sensor = "sensor." + self._name + SENSOR_NEXT_TIDE_SUFFIX

async_track_state_change_event(
self._hass,
Expand Down Expand Up @@ -1339,9 +1338,7 @@ def _async_worldtidesinfo_sensor_state_listener(self, event):
async def async_added_to_hass(self):
"""Handle added to Hass."""
await super().async_added_to_hass()
_LOGGER.info(
"add entity %s",
self.entity_id)
_LOGGER.info("add entity %s", self.entity_id)

previous_ref_lat = None
previous_ref_long = None
Expand Down

0 comments on commit f0aa67c

Please sign in to comment.