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

Update device model queries to include relevant Variable Attribute type #164

Open
wants to merge 1 commit into
base: rc-1.0.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const CONSTRUCT_CHARGING_STATION_VARIABLE_ATTRIBUTES_QUERY = (
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
left join "Evses" e on c."evseDatabaseId" = e."databaseId"
where va."stationId" = '${stationId}' and e."id" is not null
where va."stationId" = '${stationId}' and
e."id" is not null
), ''
) as evse_ids_string,
coalesce(
Expand All @@ -57,7 +58,10 @@ export const CONSTRUCT_CHARGING_STATION_VARIABLE_ATTRIBUTES_QUERY = (
from "VariableAttributes" va
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
where va."stationId" = '${stationId}' and c."name" = 'AuthCtrlr' and v."name" = 'AuthorizeRemoteStart'
where va."stationId" = '${stationId}' and
va."type" = 'Actual' and
c."name" = 'AuthCtrlr' and
v."name" = 'AuthorizeRemoteStart'
), 'FALSE'
) as authorize_remote_start,
coalesce(
Expand All @@ -66,7 +70,10 @@ export const CONSTRUCT_CHARGING_STATION_VARIABLE_ATTRIBUTES_QUERY = (
from "VariableAttributes" va
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
where va."stationId" = '${stationId}' and c."name" = 'BayOccupancySensor' and v."name" = 'Active'
where va."stationId" = '${stationId}' and
va."type" = 'Actual' and
c."name" = 'BayOccupancySensor' and
v."name" = 'Active'
), 'FALSE'
) as bay_occupancy_sensor_active,
coalesce(
Expand All @@ -75,7 +82,10 @@ export const CONSTRUCT_CHARGING_STATION_VARIABLE_ATTRIBUTES_QUERY = (
from "VariableAttributes" va
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
where va."stationId" = '${stationId}' and c."name" = 'TokenReader' and v."name" = 'Enabled'
where va."stationId" = '${stationId}' and
va."type" = 'Actual' and
c."name" = 'TokenReader' and
v."name" = 'Enabled'
), 'FALSE'
) as token_reader_enabled;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export const CONSTRUCT_CONNECTOR_VARIABLE_ATTRIBUTES_QUERY = (
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
left join "Evses" e on c."evseDatabaseId" = e."databaseId"
where va."stationId" = '${stationId}' and e."id" = ${evseComponentId} and e."connectorId" = ${connectorId} and c."name" = 'Connector' and v."name" = 'ConnectorType'
where va."stationId" = '${stationId}' and
va."type" = 'Actual' and
e."id" = ${evseComponentId} and
e."connectorId" = ${connectorId} and
c."name" = 'Connector' and
v."name" = 'ConnectorType'
), 'Unknown'
) as connector_type,
coalesce(
Expand All @@ -48,7 +53,12 @@ export const CONSTRUCT_CONNECTOR_VARIABLE_ATTRIBUTES_QUERY = (
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
left join "Evses" e on c."evseDatabaseId" = e."databaseId"
where va."stationId" = '${stationId}' and e."id" = ${evseComponentId} and e."connectorId" = ${connectorId} and c."name" = 'Connector' and v."name" = 'AvailabilityState'
where va."stationId" = '${stationId}' and
va."type" = 'Actual' and
e."id" = ${evseComponentId} and
e."connectorId" = ${connectorId} and
c."name" = 'Connector' and
v."name" = 'AvailabilityState'
), 'Unavailable'
) as connector_availability_state;
`;
42 changes: 32 additions & 10 deletions 00_Base/src/model/variableattributes/EvseVariableAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ export const CONSTRUCT_EVSE_VARIABLE_ATTRIBUTES_QUERY = (
from
coalesce(
(
select string_agg(distinct e."connectorId"::text, ',') from "VariableAttributes" va
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
left join "Evses" e on c."evseDatabaseId" = e."databaseId"
where va."stationId" = '${stationId}' and e."connectorId" is not null
select string_agg(distinct e."connectorId"::text, ',')
from "VariableAttributes" va
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
left join "Evses" e on c."evseDatabaseId" = e."databaseId"
where va."stationId" = '${stationId}' and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question: why does this query as well as query for evse_ids_string don't need to add va."type" = 'Actual' and?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it's the unique set of the evse ids, we don't necessarily have to target the type since if we pull let's say variable attributes of type Actual and Target with the same evse, they'll collapse into one evse in the set 👍

e."connectorId" is not null
), ''
) as connector_ids_string,
coalesce(
Expand All @@ -66,7 +68,11 @@ export const CONSTRUCT_EVSE_VARIABLE_ATTRIBUTES_QUERY = (
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
left join "Evses" e on c."evseDatabaseId" = e."databaseId"
where va."stationId" = '${stationId}' and e."id" = ${evseComponentId} and c."name" = 'EVSE' and v."name" = 'AvailabilityState'
where va."stationId" = '${stationId}' and
va."type" = 'Actual' and
e."id" = ${evseComponentId} and
c."name" = 'EVSE' and
v."name" = 'AvailabilityState'
), 'Unavailable'
) as evse_availability_state,
coalesce(
Expand All @@ -76,7 +82,11 @@ export const CONSTRUCT_EVSE_VARIABLE_ATTRIBUTES_QUERY = (
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
left join "Evses" e on c."evseDatabaseId" = e."databaseId"
where va."stationId" = '${stationId}' and e."id" = ${evseComponentId} and c."name" = 'EVSE' and v."name" = 'EvseId'
where va."stationId" = '${stationId}' and
va."type" = 'Actual' and
e."id" = ${evseComponentId} and
c."name" = 'EVSE' and
v."name" = 'EvseId'
), 'Unknown'
) as evse_id,
coalesce(
Expand All @@ -86,7 +96,11 @@ export const CONSTRUCT_EVSE_VARIABLE_ATTRIBUTES_QUERY = (
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
left join "Evses" e on c."evseDatabaseId" = e."databaseId"
where va."stationId" = '${stationId}' and e."id" = ${evseComponentId} and c."name" = 'EVSE' and v."name" = 'DCVoltage'
where va."stationId" = '${stationId}' and
va."type" = 'MaxSet' and
e."id" = ${evseComponentId} and
c."name" = 'EVSE' and
v."name" = 'DCVoltage'
), '0'
) as evse_dc_voltage,
coalesce(
Expand All @@ -96,7 +110,11 @@ export const CONSTRUCT_EVSE_VARIABLE_ATTRIBUTES_QUERY = (
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
left join "Evses" e on c."evseDatabaseId" = e."databaseId"
where va."stationId" = '${stationId}' and e."id" = ${evseComponentId} and c."name" = 'EVSE' and v."name" = 'DCCurrent'
where va."stationId" = '${stationId}' and
va."type" = 'MaxSet' and
e."id" = ${evseComponentId} and
c."name" = 'EVSE' and
v."name" = 'DCCurrent'
), '0'
) as evse_dc_current,
coalesce(
Expand All @@ -106,7 +124,11 @@ export const CONSTRUCT_EVSE_VARIABLE_ATTRIBUTES_QUERY = (
left join "Variables" v on va."variableId" = v."id"
left join "Components" c on va."componentId" = c."id"
left join "Evses" e on c."evseDatabaseId" = e."databaseId"
where va."stationId" = '${stationId}' and e."id" = 1 and c."name" = 'EVSE' and v."name" = 'Power'
where va."stationId" = '${stationId}' and
va."type" = 'MaxSet' and
e."id" = 1 and
c."name" = 'EVSE' and
v."name" = 'Power'
), '0'
) as evse_power;
`;
Loading