Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: Using unit based functions #223

Open
fuatakgun opened this issue Dec 29, 2022 · 0 comments
Open

Discussion: Using unit based functions #223

fuatakgun opened this issue Dec 29, 2022 · 0 comments

Comments

@fuatakgun
Copy link
Member

Current usage:

 vehicle.fuel_driving_range = 
(get_child_value(state,"vehicleStatus.dte.value",),DISTANCE_UNITS[get_child_value(state, "vehicleStatus.dte.unit")])


vehicle.ev_target_range_charge_DC = (
            get_child_value(
                state,
                "vehicleStatus.evStatus.reservChargeInfos.targetSOClist.0.dte.rangeByFuel.totalAvailableRange.value",
            ),
            DISTANCE_UNITS[
                get_child_value(
                    state,
                    "vehicleStatus.evStatus.reservChargeInfos.targetSOClist.0.dte.rangeByFuel.totalAvailableRange.unit",
                )
            ],
        )

New proposal:

@dataclass
class UnitMapper:
  value_field: str
  unit_field: str = None
  def __post_init__(self):
        if self.unit_field is None:
          splitted = self.value_field.rsplit(".", 1)
          splitted[1] = "unit"
          self.unit_field = ".".join(b)

class UnitBasedFieldDefinition(Enum):
  fuel_driving_range= UnitMapper("vehicleStatus.dte.value")
  ev_target_range_charge_DC= UnitMapper("vehicleStatus.evStatus.reservChargeInfos.targetSOClist.0.dte.rangeByFuel.totalAvailableRange.value")
  some_other = UnitMapper("vehicleStatus.field","VehicleStatus.some_other_unit_field")

for key, value in UnitBasedFieldDefinition:
  setattr(vehicle, key, get_child_value(value.value_field), get_child_value(value.unit_field))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant