hd2api.models.ABC package

Submodules

hd2api.models.ABC.model module

class hd2api.models.ABC.model.BaseApiModel(*, retrieved_at: datetime | None = None, time_delta: timedelta | None = None, **data)

Bases: BaseModel

Base model class for everything returend by the api. Features the retrieved_at and time_delta fields.

get(attr, default=None)
get_extra_fields() str

Print out all additional fields.

get_time_delta(other: BaseApiModel) timedelta | None

Calculate the time difference between the retrieved_at times of two BaseApiModel instances.

Parameters:

other (BaseApiModel) – The other instance of BaseApiModel to compare with.

Returns:

The time difference if both retrieved_at values are not None, otherwise None.

Return type:

Optional[timedelta]

model_config = {'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

retrieved_at: datetime | None
set(attr, new=None)
time_delta: timedelta | None
class hd2api.models.ABC.model.HealthMixin

Bases: object

get_health_percent(health: int | None, roundby=5)

Get health divided by the current max health.

Parameters:
  • health (Optional[int]) – The current health value to consider.

  • roundby (int, optional) – The number of decimal places to round the result. Defaults to 5.

Returns:

The health percentage rounded to the specified number of decimal places.

Return type:

float

health: int
health_percent()

Calculate the health percentage based on current health and maximum health.

Returns:

The health percentage rounded to three decimal places.

Return type:

float

maxHealth: int

Module contents